mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-02-25 14:26:57 +00:00
i386: Change X86CPUDefinition::model_id to const char*
It is valid to have a 48-character model ID on CPUID, however the definition of X86CPUDefinition::model_id is char[48], which can make the compiler drop the null terminator from the string. If a CPU model happens to have 48 bytes on model_id, "-cpu help" will print garbage and the object_property_set_str() call at x86_cpu_load_def() will read data outside the model_id array. We could increase the array size to 49, but this would mean the compiler would not issue a warning if a 49-char string is used by mistake for model_id. To make things simpler, simply change model_id to be const char*, and validate the string length using an assert() on x86_register_cpudef_type(). Backports commit 4b220d88ba76fb2623ce4b8ba1f1eea66b82144e from qemu
This commit is contained in:
parent
d89704eb0f
commit
181524d695
|
@ -883,7 +883,7 @@ struct X86CPUDefinition {
|
|||
int model;
|
||||
int stepping;
|
||||
FeatureWordArray features;
|
||||
char model_id[48];
|
||||
const char *model_id;
|
||||
bool cache_info_passthrough;
|
||||
};
|
||||
|
||||
|
@ -1094,6 +1094,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
|
|||
// FEAT_1_EDX
|
||||
I486_FEATURES,
|
||||
},
|
||||
"",
|
||||
},
|
||||
{
|
||||
"pentium",
|
||||
|
@ -1104,6 +1105,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
|
|||
// FEAT_1_EDX
|
||||
PENTIUM_FEATURES,
|
||||
},
|
||||
"",
|
||||
},
|
||||
{
|
||||
"pentium2",
|
||||
|
@ -1114,6 +1116,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
|
|||
// FEAT_1_EDX
|
||||
PENTIUM2_FEATURES,
|
||||
},
|
||||
"",
|
||||
},
|
||||
{
|
||||
"pentium3",
|
||||
|
@ -1124,6 +1127,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
|
|||
// FEAT_1_EDX
|
||||
PENTIUM3_FEATURES,
|
||||
},
|
||||
"",
|
||||
},
|
||||
{
|
||||
"athlon",
|
||||
|
@ -2526,6 +2530,9 @@ static void x86_register_cpudef_type(struct uc_struct *uc, X86CPUDefinition *def
|
|||
x86_cpu_cpudef_class_init,
|
||||
};
|
||||
|
||||
/* catch mistakes instead of silently truncating model_id when too long */
|
||||
assert(def->model_id && strlen(def->model_id) <= 48);
|
||||
|
||||
type_register(uc, &ti);
|
||||
g_free(typename);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue