]> git.proxmox.com Git - qemu.git/commitdiff
qemu-char: Check for missing backend name
authorStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Sat, 22 Jan 2011 13:07:26 +0000 (13:07 +0000)
committerAurelien Jarno <aurelien@aurel32.net>
Sun, 20 Feb 2011 17:26:41 +0000 (18:26 +0100)
Check if the backend option is missing before searching the backend
table.  This fixes a NULL pointer dereference when QEMU is invoked with
the following invalid command-line:

  $ qemu -chardev id=foo,path=/tmp/socket

Previously QEMU would segfault, now it produces this error message:

  chardev: "foo" missing backend

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
qemu-char.c

index ee4f4cab2def457357e5ede4801f2ae61dc85a7d..bd4e944e1d0b42a99822c4d4dcbcee3ec21d1676 100644 (file)
@@ -2506,6 +2506,11 @@ CharDriverState *qemu_chr_open_opts(QemuOpts *opts,
         return NULL;
     }
 
+    if (qemu_opt_get(opts, "backend") == NULL) {
+        fprintf(stderr, "chardev: \"%s\" missing backend\n",
+                qemu_opts_id(opts));
+        return NULL;
+    }
     for (i = 0; i < ARRAY_SIZE(backend_table); i++) {
         if (strcmp(backend_table[i].name, qemu_opt_get(opts, "backend")) == 0)
             break;