Patchwork [1/7] qemu-option: Fix qemu_opts_find() for null id arguments

login
register
mail settings
Submitter Markus Armbruster
Date July 4, 2013, 1:09 p.m.
Message ID <1372943363-24081-2-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/256895/
State New
Headers show

Comments

Markus Armbruster - July 4, 2013, 1:09 p.m.
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>
---
 util/qemu-option.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
Peter Maydell - July 4, 2013, 2:40 p.m.
On 4 July 2013 14:09, Markus Armbruster <armbru@redhat.com> wrote:
> 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>

-- PMM

Patch

diff --git a/util/qemu-option.c b/util/qemu-option.c
index 412c425..2715f27 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -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;
 }