qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] vl.c: Avoid segfault when started with no argum


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH] vl.c: Avoid segfault when started with no arguments
Date: Fri, 24 Feb 2012 13:49:14 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Lightning/1.0b2 Thunderbird/3.1.15

On 02/22/2012 04:40 PM, Peter Maydell wrote:
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<address@hidden>

Applied.  Thanks.

Regards,

Anthony Liguori

---
Oops, sorry about that... I must have tested the case where you do
pass -kernel&co but forgot to test the case where you don't.

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

diff --git a/vl.c b/vl.c
index 7a8cc08..8375576 100644
--- a/vl.c
+++ b/vl.c
@@ -2188,7 +2188,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;
@@ -3247,12 +3247,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 = "";
      }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]