vl.c: Avoid segfault when started with no arguments

Fix a bug (introduced in commit a0abe47) where a command line which
specified no machine arguments (either explicitly or implicitly via
-kernel &co) would result in a segfault because of a NULL pointer
returned from qemu_opts_find(qemu_find_opts("machine"), 0).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
master
Peter Maydell 2012-02-22 22:40:00 +00:00 committed by Anthony Liguori
parent 9ebe95fb60
commit 967c0da73a
1 changed files with 10 additions and 7 deletions

17
vl.c
View File

@ -2261,7 +2261,7 @@ int main(int argc, char **argv, char **envp)
DisplayState *ds; DisplayState *ds;
DisplayChangeListener *dcl; DisplayChangeListener *dcl;
int cyls, heads, secs, translation; int cyls, heads, secs, translation;
QemuOpts *hda_opts = NULL, *opts; QemuOpts *hda_opts = NULL, *opts, *machine_opts;
QemuOptsList *olist; QemuOptsList *olist;
int optind; int optind;
const char *optarg; const char *optarg;
@ -3320,12 +3320,15 @@ int main(int argc, char **argv, char **envp)
exit(1); exit(1);
} }
kernel_filename = qemu_opt_get(qemu_opts_find(qemu_find_opts("machine"), machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
0), "kernel"); if (machine_opts) {
initrd_filename = qemu_opt_get(qemu_opts_find(qemu_find_opts("machine"), kernel_filename = qemu_opt_get(machine_opts, "kernel");
0), "initrd"); initrd_filename = qemu_opt_get(machine_opts, "initrd");
kernel_cmdline = qemu_opt_get(qemu_opts_find(qemu_find_opts("machine"), kernel_cmdline = qemu_opt_get(machine_opts, "append");
0), "append"); } else {
kernel_filename = initrd_filename = kernel_cmdline = NULL;
}
if (!kernel_cmdline) { if (!kernel_cmdline) {
kernel_cmdline = ""; kernel_cmdline = "";
} }