diff mbox

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

Message ID 1372943363-24081-2-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster July 4, 2013, 1:09 p.m. UTC
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(-)

Comments

Peter Maydell July 4, 2013, 2:40 p.m. UTC | #1
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
diff mbox

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;
 }