aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2012-02-22 22:40:00 +0000
committerAnthony Liguori <aliguori@us.ibm.com>2012-02-24 13:36:06 -0600
commit967c0da73a7b0da186baba6632301d83644a570c (patch)
tree0425c547fd37766839b52dd4e398e3cd304ceb94
parent9ebe95fb606a8d6bebe29de3efc9b506c6428c62 (diff)
downloadqemu-967c0da73a7b0da186baba6632301d83644a570c.zip
qemu-967c0da73a7b0da186baba6632301d83644a570c.tar.gz
qemu-967c0da73a7b0da186baba6632301d83644a570c.tar.bz2
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>
-rw-r--r--vl.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/vl.c b/vl.c
index e1a1e89..1d4c350 100644
--- a/vl.c
+++ b/vl.c
@@ -2261,7 +2261,7 @@ int main(int argc, char **argv, char **envp)
DisplayState *ds;
DisplayChangeListener *dcl;
int cyls, heads, secs, translation;
- QemuOpts *hda_opts = NULL, *opts;
+ QemuOpts *hda_opts = NULL, *opts, *machine_opts;
QemuOptsList *olist;
int optind;
const char *optarg;
@@ -3320,12 +3320,15 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
- kernel_filename = qemu_opt_get(qemu_opts_find(qemu_find_opts("machine"),
- 0), "kernel");
- initrd_filename = qemu_opt_get(qemu_opts_find(qemu_find_opts("machine"),
- 0), "initrd");
- kernel_cmdline = qemu_opt_get(qemu_opts_find(qemu_find_opts("machine"),
- 0), "append");
+ machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
+ if (machine_opts) {
+ kernel_filename = qemu_opt_get(machine_opts, "kernel");
+ initrd_filename = qemu_opt_get(machine_opts, "initrd");
+ kernel_cmdline = qemu_opt_get(machine_opts, "append");
+ } else {
+ kernel_filename = initrd_filename = kernel_cmdline = NULL;
+ }
+
if (!kernel_cmdline) {
kernel_cmdline = "";
}