From 1bbd185fa826a2da7c6089b968f9f7d08438c2c8 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Sat, 22 Jan 2011 13:07:26 +0000 Subject: 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 Signed-off-by: Stefan Hajnoczi Signed-off-by: Aurelien Jarno --- qemu-char.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'qemu-char.c') diff --git a/qemu-char.c b/qemu-char.c index ee4f4ca..bd4e944 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -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; -- cgit v1.1