Skip to contentSkip to conversation

cpuid: Null terminate x86 CPU string.

PATCH Applied Sitsofe Wheeler 2 participants 3 messages Feb 13, 2014 – Feb 14, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpuid: Null terminate x86 CPU string.

---
 arch/arch-x86-common.h | 1 +
 1 file changed, 1 insertion(+)
arch/arch-x86-common.h +1 -0
index 179572d..26a14a8 100644
@@ -60,6 +60,7 @@ static inline int arch_init(char *envp[])
 			 (unsigned int *) &str[8],
 			 (unsigned int *) &str[4]);
 
+	str[11] = '\0';
 	if (!strcmp(str, "GenuineIntel"))
 		tsc_reliable = arch_init_intel(level);
 	else if (!strcmp(str, "AuthenticAMD"))
Signature · 4 lines
1.8.5.3

-- 
Sitsofe | http://sucs.org/~sits/
Applied
#1 lore raw
Quoted 10 lines · Sitsofe Wheeler
---
 arch/arch-x86-common.h | 1 +
 1 file changed, 1 insertion(+)
arch/arch-x86-common.h +0 -0
index 179572d..26a14a8 100644

arch/arch-x86-common.h static inline int arch_init(char *envp[]) · line 66

Quoted 7 lines
arch/arch-x86-common.h +1 -0
@@ -60,6 +60,7 @@ static inline int arch_init(char *envp[])
 			 (unsigned int *) &str[8],
 			 (unsigned int *) &str[4]);
 
+	str[11] = '\0';
 	if (!strcmp(str, "GenuineIntel"))
 		tsc_reliable = arch_init_intel(level);
 	else if (!strcmp(str, "AuthenticAMD"))

Applied, thanks.

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 14 lines · Jens Axboe
Quoted 13 lines · Sitsofe Wheeler
---
 arch/arch-x86-common.h | 1 +
 1 file changed, 1 insertion(+)
arch/arch-x86-common.h +0 -0
index 179572d..26a14a8 100644
@@ -60,6 +60,7 @@ static inline int arch_init(char *envp[])
 			 (unsigned int *) &str[8],
 			 (unsigned int *) &str[4]);
 
Quoted 6 lines

arch/arch-x86-common.h static inline int arch_init(char *envp[]) · line 66

Quoted 4 lines
arch/arch-x86-common.h +1 -0
+	str[11] = '\0';
 	if (!strcmp(str, "GenuineIntel"))
 		tsc_reliable = arch_init_intel(level);
 	else if (!strcmp(str, "AuthenticAMD"))

Applied, thanks.

Oops, this one was buggy - if we want the string null terminated, there needs to be room for 13 characters. It needs to look like this:

arch/arch-x86-common.h +2 -2
index 26a14a823750..31aa79f1b573 100644
@@ -54,13 +54,13 @@ static inline int arch_init_amd(unsigned int level)
 static inline int arch_init(char *envp[])
 {
 	unsigned int level;
-	char str[12];
+	char str[13];
 
 	cpuid(0, &level, (unsigned int *) &str[0],
 			 (unsigned int *) &str[8],
 			 (unsigned int *) &str[4]);
 
-	str[11] = '\0';
+	str[12] = '\0';
 	if (!strcmp(str, "GenuineIntel"))
 		tsc_reliable = arch_init_intel(level);
 	else if (!strcmp(str, "AuthenticAMD"))
Signature · 1 line
Jens Axboe