From cd0d1993f4ef30f531c727ef50206361adba1816 Mon Sep 17 00:00:00 2001 From: Mike McCormack Date: Tue, 29 Jun 2010 17:38:23 +0900 Subject: [PATCH] Fix null pointer dereference when parsing chardevs without a backend option. Signed-off-by: Mike McCormack --- qemu-char.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/qemu-char.c b/qemu-char.c index 33f2237..78111db 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2441,6 +2441,7 @@ CharDriverState *qemu_chr_open_opts(QemuOpts *opts, void (*init)(struct CharDriverState *s)) { CharDriverState *chr; + const char *backend; int i; if (qemu_opts_id(opts) == NULL) { @@ -2448,8 +2449,14 @@ CharDriverState *qemu_chr_open_opts(QemuOpts *opts, return NULL; } + backend = qemu_opt_get(opts, "backend"); + if (!backend) { + fprintf(stderr, "chardev: backend option not specified\n"); + return NULL; + } + for (i = 0; i < ARRAY_SIZE(backend_table); i++) { - if (strcmp(backend_table[i].name, qemu_opt_get(opts, "backend")) == 0) + if (strcmp(backend_table[i].name, backend) == 0) break; } if (i == ARRAY_SIZE(backend_table)) { -- 2.7.4