Skip to content

Commit a6c522c

Browse files
committed
Solve dmi_memory_device_extended_size WORD issue
In case 17: dmi_memory_device_extended_size(sect_n, WORD(data + 0x1C)); may cause memory capcity read error. This because WORD and DWORD have different byte size, the DWORD is double long of WORD. After SMBIOS v2.8.0, the structures assume to be little-endian order. So redefine the WORD and DWORD in types.h. Signed-off-by: Zhongze Hu <joshuahu@tencent.com>
1 parent 50e9593 commit a6c522c

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/dmidecode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5378,7 +5378,7 @@ xmlNode *dmi_decode(xmlNode *prnt_n, dmi_codes_major *dmiMajor, struct dmi_heade
53785378
dmi_memory_device_width(sect_n, "TotalWidth", WORD(data + 0x08));
53795379
dmi_memory_device_width(sect_n, "DataWidth", WORD(data + 0x0A));
53805380
if (h->length >= 0x20 && WORD(data + 0x0C) == 0x7FFF) {
5381-
dmi_memory_device_extended_size(sect_n, WORD(data + 0x1C));
5381+
dmi_memory_device_extended_size(sect_n, DWORD(data + 0x1C));
53825382
} else {
53835383
dmi_memory_device_size(sect_n, WORD(data + 0x0C));
53845384
}

src/types.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,18 @@ static inline u64 U64(u32 low, u32 high)
6969
}
7070
#endif
7171

72-
#ifdef ALIGNMENT_WORKAROUND
73-
# ifdef BIGENDIAN
74-
# define WORD(x) (u16)((x)[1]+((x)[0]<<8))
75-
# define DWORD(x) (u32)((x)[3]+((x)[2]<<8)+((x)[1]<<16)+((x)[0]<<24))
76-
# define QWORD(x) (U64(DWORD(x+4), DWORD(x)))
77-
# else /* BIGENDIAN */
78-
# define WORD(x) (u16)((x)[0]+((x)[1]<<8))
79-
# define DWORD(x) (u32)((x)[0]+((x)[1]<<8)+((x)[2]<<16)+((x)[3]<<24))
80-
# define QWORD(x) (U64(DWORD(x), DWORD(x+4)))
81-
# endif /* BIGENDIAN */
82-
#else /* ALIGNMENT_WORKAROUND */
72+
/*
73+
* Per SMBIOS v2.8.0 and later, all structures assume a little-endian
74+
* ordering convention.
75+
*/
76+
#if defined(ALIGNMENT_WORKAROUND) || defined(BIGENDIAN)
77+
#define WORD(x) (u16)((x)[0] + ((x)[1] << 8))
78+
#define DWORD(x) (u32)((x)[0] + ((x)[1] << 8) + ((x)[2] << 16) + ((x)[3] << 24))
79+
#define QWORD(x) (U64(DWORD(x), DWORD(x + 4)))
80+
#else /* ALIGNMENT_WORKAROUND || BIGENDIAN */
8381
#define WORD(x) (u16)(*(const u16 *)(x))
8482
#define DWORD(x) (u32)(*(const u32 *)(x))
8583
#define QWORD(x) (*(const u64 *)(x))
86-
#endif /* ALIGNMENT_WORKAROUND */
84+
#endif /* ALIGNMENT_WORKAROUND || BIGENDIAN */
8785

8886
#endif

0 commit comments

Comments
 (0)