[PAL] Null-terminate PAL_CPU_INFO strings

This commit is contained in:
Michał Kowalczyk
2019-02-14 22:00:09 +01:00
parent 88dd3f0ae7
commit bb18fc957d
3 changed files with 18 additions and 6 deletions
+6 -2
View File
@@ -340,21 +340,25 @@ void _DkGetCPUInfo (PAL_CPU_INFO * ci)
{
unsigned int words[WORD_NUM];
char * vendor_id = malloc(12);
const size_t VENDOR_ID_SIZE = 13;
char* vendor_id = malloc(VENDOR_ID_SIZE);
cpuid(2, 0, words, 0);
FOUR_CHARS_VALUE(&vendor_id[0], words[WORD_EBX]);
FOUR_CHARS_VALUE(&vendor_id[4], words[WORD_EDX]);
FOUR_CHARS_VALUE(&vendor_id[8], words[WORD_ECX]);
vendor_id[VENDOR_ID_SIZE - 1] = '\0';
ci->cpu_vendor = vendor_id;
char * brand = malloc(48);
const size_t BRAND_SIZE = 49;
char* brand = malloc(BRAND_SIZE);
cpuid(-2, 0x80000002, words, 0);
memcpy(&brand[ 0], words, sizeof(unsigned int) * WORD_NUM);
cpuid(-2, 0x80000003, words, 0);
memcpy(&brand[16], words, sizeof(unsigned int) * WORD_NUM);
cpuid(-2, 0x80000004, words, 0);
memcpy(&brand[32], words, sizeof(unsigned int) * WORD_NUM);
brand[BRAND_SIZE - 1] = '\0';
ci->cpu_brand = brand;
cpuid(2, 1, words, 0);
+6 -2
View File
@@ -292,23 +292,27 @@ void _DkGetCPUInfo (PAL_CPU_INFO * ci)
{
unsigned int words[WORD_NUM];
char * vendor_id = malloc(12);
const size_t VENDOR_ID_SIZE = 13;
char* vendor_id = malloc(VENDOR_ID_SIZE);
cpuid(0, 0, words);
FOUR_CHARS_VALUE(&vendor_id[0], words[WORD_EBX]);
FOUR_CHARS_VALUE(&vendor_id[4], words[WORD_EDX]);
FOUR_CHARS_VALUE(&vendor_id[8], words[WORD_ECX]);
vendor_id[VENDOR_ID_SIZE - 1] = '\0';
ci->cpu_vendor = vendor_id;
// Must be an Intel CPU
assert(!memcmp(vendor_id, "GenuineIntel", 12));
char * brand = malloc(48);
const size_t BRAND_SIZE = 49;
char* brand = malloc(BRAND_SIZE);
cpuid(0x80000002, 0, words);
memcpy(&brand[ 0], words, sizeof(unsigned int) * WORD_NUM);
cpuid(0x80000003, 0, words);
memcpy(&brand[16], words, sizeof(unsigned int) * WORD_NUM);
cpuid(0x80000004, 0, words);
memcpy(&brand[32], words, sizeof(unsigned int) * WORD_NUM);
brand[BRAND_SIZE - 1] = '\0';
ci->cpu_brand = brand;
/* According to SDM: EBX[15:0] is to enumerate processor topology
+6 -2
View File
@@ -389,21 +389,25 @@ void _DkGetCPUInfo (PAL_CPU_INFO * ci)
{
unsigned int words[WORD_NUM];
char * vendor_id = malloc(12);
const size_t VENDOR_ID_SIZE = 13;
char* vendor_id = malloc(VENDOR_ID_SIZE);
cpuid(0, 0, words);
FOUR_CHARS_VALUE(&vendor_id[0], words[WORD_EBX]);
FOUR_CHARS_VALUE(&vendor_id[4], words[WORD_EDX]);
FOUR_CHARS_VALUE(&vendor_id[8], words[WORD_ECX]);
vendor_id[VENDOR_ID_SIZE - 1] = '\0';
ci->cpu_vendor = vendor_id;
char * brand = malloc(48);
const size_t BRAND_SIZE = 49;
char* brand = malloc(BRAND_SIZE);
cpuid(0x80000002, 0, words);
memcpy(&brand[ 0], words, sizeof(unsigned int) * WORD_NUM);
cpuid(0x80000003, 0, words);
memcpy(&brand[16], words, sizeof(unsigned int) * WORD_NUM);
cpuid(0x80000004, 0, words);
memcpy(&brand[32], words, sizeof(unsigned int) * WORD_NUM);
brand[BRAND_SIZE - 1] = '\0';
ci->cpu_brand = brand;
if (!memcmp(vendor_id, "GenuineIntel", 12)) {