]> git.proxmox.com Git - qemu.git/commitdiff
vl.c: Exit QEMU early if no machine is found
authorDunrong Huang <riegamaths@gmail.com>
Mon, 23 Jul 2012 16:42:20 +0000 (00:42 +0800)
committerStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Fri, 10 Aug 2012 13:28:11 +0000 (14:28 +0100)
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.

Markus Armbruster <armbru@redhat.com> adds that the segfault can be
reproduced as follows:

  $ qemu-system-xtensa -cpu help

Signed-off-by: Dunrong Huang <riegamaths@gmail.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
vl.c

diff --git a/vl.c b/vl.c
index a4a520fb7e6ce49019ddd5d440e6666784f0710f..48714288646c57c433d7a3f4906f213bd489f25b 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -3204,6 +3204,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);
     }
@@ -3246,11 +3251,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.