Remove the FIELD_OFFSET macro and use the offsetof() operator instead.
The FIELD_OFFSET was dereferencing a null pointer in order to compute the offset of a field within the structure, but dereferencing a null pointer is considered undefined behavior in C and triggers the undefined behavior sanitizer (UBSAN).
@@ -67,9 +67,6 @@ typedef int32_t LONG;
typedef uint32_t ULONG;
typedef uint64_t ULONGLONG;
-
-#define FIELD_OFFSET(type, field) ((size_t)&(((type *)0)->field))
-
#ifndef _MAC
#define IMAGE_DOS_SIGNATURE 0x5A4D // MZ
@@ -318,7 +315,7 @@ typedef struct _IMAGE_NT_HEADERS64 {
#define IMAGE_FIRST_SECTION( ntheader ) ((PIMAGE_SECTION_HEADER) \
((BYTE*) ntheader + \
- FIELD_OFFSET( IMAGE_NT_HEADERS32, OptionalHeader ) + \
+ offsetof(IMAGE_NT_HEADERS32, OptionalHeader) + \
yr_le16toh(((PIMAGE_NT_HEADERS32)(ntheader))->FileHeader.SizeOfOptionalHeader) \
))
