x86/cpuid: A few trivial fixes
cover x86/cpuid: A few trivial fixes
Markus Armbruster (3):
x86/cpuid: Convert remaining strdup() to g_strdup() x86/cpuid: Plug memory leak in cpudef_setfield() x86/cpuid: Fix crash on -cpu ""
target-i386/cpuid.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)
Signature · 1 line
1.7.6.4
PATCH 1/3 x86/cpuid: Convert remaining strdup() to g_strdup()
Fixes missing error checking.
--- target-i386/cpuid.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
target-i386/cpuid.c +4 -4
@@ -600,7 +600,7 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)unsigned int i;x86_def_t *def; -char *s =strdup (cpu_model); +char *s =g_strdup (cpu_model);char *featurestr, *name =strtok (s,"," );/* Features to be added*/ uint32_t plus_features =0 , plus_ext_features =0 ;
@@ -746,11 +746,11 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)if (check_features_against_host (x86_cpu_def) && enforce_cpuid) goto error; } -free (s); +g_free (s);return 0 ; error: -free (s); +g_free (s);return -1 ; }
@@ -969,7 +969,7 @@ static int cpudef_setfield(const char *name, const char *str, void *opaque)int err =0 ;if (!strcmp (name,"name" )) { - def->name =strdup (str); + def->name =g_strdup (str); }else if (!strcmp (name,"model_id" )) {strncpy (def->model_id, str,sizeof (def->model_id)); }else if (!strcmp (name,"level" )) {
Signature · 1 line
1.7.6.4
PATCH 2/3 x86/cpuid: Plug memory leak in cpudef_setfield()
In reply to Markus ArmbrusterTo reproduce the leak, put two name options into the same [cpudef] section of target-x86_64.conf.
--- target-i386/cpuid.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
target-i386/cpuid.c +1 -0
@@ -969,6 +969,7 @@ static int cpudef_setfield(const char *name, const char *str, void *opaque)int err =0 ;if (!strcmp (name,"name" )) { +g_free ((void *)def->name); def->name =g_strdup (str); }else if (!strcmp (name,"model_id" )) {strncpy (def->model_id, str,sizeof (def->model_id));
Signature · 1 line
1.7.6.4
PATCH 3/3 x86/cpuid: Fix crash on -cpu ""
In reply to Markus ArmbrusterSpotted by Coverity.
--- target-i386/cpuid.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
target-i386/cpuid.c +2 -2
@@ -613,9 +613,9 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char *cpu_model)uint32_t numvalue;for (def = x86_defs; def; def = def->next) -if (!strcmp (name, def->name)) +if (name && !strcmp (name, def->name))break ; -if (kvm_enabled () &&strcmp (name,"host" ) ==0 ) { +if (kvm_enabled () && name &&strcmp (name,"host" ) ==0 ) {cpu_x86_fill_host (x86_cpu_def); }else if (!def) { goto error;
Signature · 1 line
1.7.6.4
Stefan Hajnoczi
AppliedQuoted 7 lines · Markus Armbruster
Markus Armbruster (3):
x86/cpuid: Convert remainingstrdup()tog_strdup()x86/cpuid: Plug memory leak incpudef_setfield()x86/cpuid: Fix crash on -cpu ""target-i386/cpuid.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)
Thanks, applied to the trivial patches tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patches
Stefan