[coreboot-gerrit] Change in coreboot[master]: arch/x86/smbios: Fix undefined behavior
Ryan Salsamendi (Code Review)
gerrit at coreboot.org
Mon Jun 12 04:03:15 CEST 2017
Ryan Salsamendi has uploaded this change for review. ( https://review.coreboot.org/20154
Change subject: arch/x86/smbios: Fix undefined behavior
......................................................................
arch/x86/smbios: Fix undefined behavior
Fixes report found by undefined behavior sanitizer. Dereferencing a
pointer that's not aligned to the size of access is undefined behavior.
The report triggered for smbios_cpu_vendor(). Also fixes the same issue
in smbios_processor_name() found by inspection.
Change-Id: I1b7d08655edce729e107a5b6e61ee509ebde33b6
Signed-off-by: Ryan Salsamendi <rsalsamendi at hotmail.com>
---
M src/arch/x86/smbios.c
1 file changed, 11 insertions(+), 7 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/54/20154/1
diff --git a/src/arch/x86/smbios.c b/src/arch/x86/smbios.c
index 0909900..fef821d 100644
--- a/src/arch/x86/smbios.c
+++ b/src/arch/x86/smbios.c
@@ -92,9 +92,9 @@
if (cpu_have_cpuid()) {
res = cpuid(0);
- _tmp[0] = res.ebx;
- _tmp[1] = res.edx;
- _tmp[2] = res.ecx;
+ memcpy(&_tmp[0], &res.ebx, sizeof(res.ebx));
+ memcpy(&_tmp[1], &res.edx, sizeof(res.edx));
+ memcpy(&_tmp[2], &res.ecx, sizeof(res.ecx));
tmp[12] = '\0';
}
@@ -113,10 +113,14 @@
if (res.eax >= 0x80000004) {
for (i = 0; i < 3; i++) {
res = cpuid(0x80000002 + i);
- _tmp[i * 4 + 0] = res.eax;
- _tmp[i * 4 + 1] = res.ebx;
- _tmp[i * 4 + 2] = res.ecx;
- _tmp[i * 4 + 3] = res.edx;
+ memcpy(&_tmp[i * 4 + 0], &res.eax,
+ sizeof(res.eax));
+ memcpy(&_tmp[i * 4 + 1], &res.ebx,
+ sizeof(res.ebx));
+ memcpy(&_tmp[i * 4 + 2], &res.ecx,
+ sizeof(res.ecx));
+ memcpy(&_tmp[i * 4 + 3], &res.edx,
+ sizeof(res.edx));
}
tmp[48] = 0;
}
--
To view, visit https://review.coreboot.org/20154
To unsubscribe, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1b7d08655edce729e107a5b6e61ee509ebde33b6
Gerrit-Change-Number: 20154
Gerrit-PatchSet: 1
Gerrit-Owner: Ryan Salsamendi <rsalsamendi at hotmail.com>
More information about the coreboot-gerrit
mailing list