qemu-option: Fix qemu_opts_find() for null id arguments
authorMarkus Armbruster <armbru@redhat.com>
Thu, 4 Jul 2013 13:09:17 +0000 (15:09 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Tue, 9 Jul 2013 18:38:56 +0000 (13:38 -0500)
Crashes when the first list member has an ID.  Admittedly nonsensical
reproducer:

$ qemu-system-x86_64 -nodefaults -machine id=foo -machine ""

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 1372943363-24081-2-git-send-email-armbru@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
util/qemu-option.c

index 412c425..2715f27 100644 (file)
@@ -706,16 +706,12 @@ QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id)
     QemuOpts *opts;
 
     QTAILQ_FOREACH(opts, &list->head, next) {
-        if (!opts->id) {
-            if (!id) {
-                return opts;
-            }
-            continue;
+        if (!opts->id && !id) {
+            return opts;
         }
-        if (strcmp(opts->id, id) != 0) {
-            continue;
+        if (opts->id && id && !strcmp(opts->id, id)) {
+            return opts;
         }
-        return opts;
     }
     return NULL;
 }