]> git.proxmox.com Git - qemu.git/commitdiff
qemu-sockets: avoid strlen of NULL pointer
authorJens Osterkamp <jens@linux.vnet.ibm.com>
Mon, 12 Apr 2010 08:51:01 +0000 (10:51 +0200)
committerAurelien Jarno <aurelien@aurel32.net>
Thu, 27 May 2010 13:52:42 +0000 (15:52 +0200)
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 <jens@linux.vnet.ibm.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
(cherry picked from commit e23a22e620e84f42bdbd473b82672654e7c8de73)

qemu-sockets.c

index a88b2a77fc535632c8db5d6a04bba1ba2bb0864e..993ce121580969c6ec9e18c5ee7b99f1c1bf3e03 100644 (file)
@@ -130,7 +130,8 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
     ai.ai_family = PF_UNSPEC;
     ai.ai_socktype = SOCK_STREAM;
 
-    if (qemu_opt_get(opts, "port") == NULL) {
+    if ((qemu_opt_get(opts, "host") == NULL) ||
+        (qemu_opt_get(opts, "port") == NULL)) {
         fprintf(stderr, "%s: host and/or port not specified\n", __FUNCTION__);
         return -1;
     }