Skip to contentSkip to conversation

vl.c: Exit QEMU early if no machine is found

PATCH Applied [email protected] 3 participants 3 messages Jul 23, 2012 – Aug 9, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vl.c: Exit QEMU early if no machine is found

From: Dunrong Huang <[email protected]>

We check whether the variable machine is NULL or not before accessing it. If machine is NULL, exit QEMU with an error, this can avoids a segfault error.

---
 vl.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
vl.c +5 -5
index 8904db1..0d145dc 100644
@@ -3205,6 +3205,11 @@ int main(int argc, char **argv, char **envp)
     }
     loc_set_none();
 
+    if (machine == NULL) {
+        fprintf(stderr, "No machine found.\n");
+        exit(1);
+    }
+
     if (machine->hw_version) {
         qemu_set_version(machine->hw_version);
     }
@@ -3247,11 +3252,6 @@ int main(int argc, char **argv, char **envp)
         data_dir = CONFIG_QEMU_DATADIR;
     }
 
-    if (machine == NULL) {
-        fprintf(stderr, "No machine found.\n");
-        exit(1);
-    }
-
     /*
      * Default to max_cpus = smp_cpus, in case the user doesn't
      * specify a max_cpus value.
Signature · 1 line
1.7.8.6
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · [email protected] writes:

From: Dunrong Huang <[email protected]>

We check whether the variable machine is NULL or not before accessing it. If machine is NULL, exit QEMU with an error, this can avoids a segfault error.

Commit message lacks detail on how to reproduce the SEGV. This does the trick:

    $ qemu-system-xtensa -cpu help
#2 lore raw
In reply to [email protected]
Quoted 10 lines · On Tue, Jul 24, 2012 at 12:42:20AM +0800, [email protected] wrote:

From: Dunrong Huang <[email protected]>

We check whether the variable machine is NULL or not before accessing it. If machine is NULL, exit QEMU with an error, this can avoids a segfault error.

---
 vl.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan