Skip to contentSkip to conversation

x86/cpuid: A few trivial fixes

PATCH Applied Markus Armbruster 2 participants 5 messages Nov 8, 2011 – Nov 9, 2011

lore
Share & tools
lore
#3 lore raw

PATCH 3/3 x86/cpuid: Fix crash on -cpu ""

In reply to Markus Armbruster

Spotted by Coverity.

---
 target-i386/cpuid.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
target-i386/cpuid.c +2 -2
index 0fce752..9fc9769 100644
@@ -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
#0 lore raw

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
#2 lore raw

PATCH 2/3 x86/cpuid: Plug memory leak in cpudef_setfield()

To 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
index 7c8f1be..0fce752 100644
@@ -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
#1 lore raw

PATCH 1/3 x86/cpuid: Convert remaining strdup() to g_strdup()

In reply to Markus Armbruster

Fixes missing error checking.

---
 target-i386/cpuid.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
target-i386/cpuid.c +4 -4
index 1e8bcff..7c8f1be 100644
@@ -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