From patchwork Wed Mar 3 14:32:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: qemu-kvm: avoid strlen of NULL pointer Date: Wed, 03 Mar 2010 04:32:43 -0000 From: Jens Osterkamp X-Patchwork-Id: 46808 Message-Id: <201003031532.43257.jens@linux.vnet.ibm.com> To: qemu-devel@nongnu.org If the user wants to create a chardev of type socket but forgets to give a host= option, qemu_opt_get returns NULL. This NULL pointer is then fed into strlen a few lines below without a check which results in a segfault. This fixes it. Signed-off-by: Jens Osterkamp --- qemu-sockets.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/qemu-sockets.c b/qemu-sockets.c index 23c3def..a191304 100644 --- a/qemu-sockets.c +++ b/qemu-sockets.c @@ -137,6 +137,9 @@ int inet_listen_opts(QemuOpts *opts, int port_offset) pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port")); addr = qemu_opt_get(opts, "host"); + if (!addr) + return -1; + to = qemu_opt_get_number(opts, "to", 0); if (qemu_opt_get_bool(opts, "ipv4", 0)) ai.ai_family = PF_INET;