From: Dunrong Huang Date: Mon, 23 Jul 2012 16:42:20 +0000 (+0800) Subject: vl.c: Exit QEMU early if no machine is found X-Git-Tag: v1.2.0-rc0~34^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fb7c269ed694c103397c5fffbfcccd3e90aed23c;p=thirdparty%2Fqemu.git vl.c: Exit QEMU early if no machine is found 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 adds that the segfault can be reproduced as follows: $ qemu-system-xtensa -cpu help Signed-off-by: Dunrong Huang Reviewed-by: Markus Armbruster Signed-off-by: Stefan Hajnoczi --- diff --git a/vl.c b/vl.c index a4a520fb7e6..48714288646 100644 --- 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.