Merge pull request #3051 from SChernykh/dev

Fixed unaligned memory read in DMI
This commit is contained in:
xmrig 2022-05-20 09:11:26 +07:00 committed by GitHub
commit 059d5d8421
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View file

@ -30,7 +30,7 @@ namespace xmrig {
template<typename T>
inline T readUnaligned(const T* ptr)
{
static_assert(std::is_integral<T>::value, "Integer type required");
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable");
T result;
memcpy(&result, ptr, sizeof(T));
@ -41,7 +41,7 @@ inline T readUnaligned(const T* ptr)
template<typename T>
inline void writeUnaligned(T* ptr, T data)
{
static_assert(std::is_integral<T>::value, "Integer type required");
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable");
memcpy(ptr, &data, sizeof(T));
}

View file

@ -28,13 +28,12 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
void randomx_set_huge_pages_jit(bool)
{
}
void randomx_set_optimized_dataset_init(int)
{
}

View file

@ -24,6 +24,7 @@
#include <cstddef>
#include <cstdint>
#include "base/tools/Alignment.h"
namespace xmrig {
@ -45,10 +46,10 @@ struct u64 {
template<typename T>
inline T dmi_get(const uint8_t *data) { return *reinterpret_cast<const T *>(data); }
inline T dmi_get(const uint8_t *data) { return readUnaligned(reinterpret_cast<const T *>(data)); }
template<typename T>
inline T dmi_get(const dmi_header *h, size_t offset) { return *reinterpret_cast<const T *>(h->data + offset); }
inline T dmi_get(const dmi_header *h, size_t offset) { return readUnaligned(reinterpret_cast<const T *>(h->data + offset)); }
const char *dmi_string(dmi_header *dm, size_t offset);