[coreboot-gerrit] Change in coreboot[master]: cpu/x86/name: Fix undefined behavior

Ryan Salsamendi (Code Review) gerrit at coreboot.org
Sun Jul 2 03:30:00 CEST 2017


Ryan Salsamendi has uploaded this change for review. ( https://review.coreboot.org/20452


Change subject: cpu/x86/name: Fix undefined behavior
......................................................................

cpu/x86/name: 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.

Change-Id: I1362a3eb8c97f5c7e848d75f8d1a219968a7ef9e
Signed-off-by: Ryan Salsamendi <rsalsamendi at hotmail.com>
---
M src/cpu/x86/name/name.c
1 file changed, 3 insertions(+), 4 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/52/20452/1

diff --git a/src/cpu/x86/name/name.c b/src/cpu/x86/name/name.c
index b59fd8b..aa1ba7a 100644
--- a/src/cpu/x86/name/name.c
+++ b/src/cpu/x86/name/name.c
@@ -21,9 +21,8 @@
 void fill_processor_name(char *processor_name)
 {
 	struct cpuid_result regs;
-	char temp_processor_name[49];
 	char *processor_name_start;
-	unsigned int *name_as_ints = (unsigned int *)temp_processor_name;
+	unsigned int name_as_ints[13];
 	int i;
 
 	for (i = 0; i < 3; i++) {
@@ -34,10 +33,10 @@
 		name_as_ints[i * 4 + 3] = regs.edx;
 	}
 
-	temp_processor_name[48] = 0;
+	name_as_ints[12] = 0;
 
 	/* Skip leading spaces. */
-	processor_name_start = temp_processor_name;
+	processor_name_start = (char *)name_as_ints;
 	while (*processor_name_start == ' ')
 		processor_name_start++;
 

-- 
To view, visit https://review.coreboot.org/20452
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1362a3eb8c97f5c7e848d75f8d1a219968a7ef9e
Gerrit-Change-Number: 20452
Gerrit-PatchSet: 1
Gerrit-Owner: Ryan Salsamendi <rsalsamendi at hotmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20170702/6e9eb33a/attachment.html>


More information about the coreboot-gerrit mailing list