Skip to contentSkip to conversation

qemu-char: Check for missing backend name

PATCH Applied Stefan Hajnoczi 2 participants 2 messages Jan 22, 2011 – Feb 20, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-char: Check for missing backend name

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

---
 qemu-char.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
qemu-char.c +5 -0
index edc9ad6..8a424d6 100644
@@ -2508,6 +2508,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;
Signature · 1 line
1.7.2.3
#1 lore raw
Quoted 6 lines · Stefan Hajnoczi

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
Quoted 8 lines

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

chardev: "foo" missing backend

---
 qemu-char.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

Thanks, applied.

Quoted 21 lines
qemu-char.c +5 -0
index edc9ad6..8a424d6 100644
@@ -2508,6 +2508,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;
Signature · 1 line
1.7.2.3
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net