]> 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>
Tue, 18 May 2010 17:49:16 +0000 (19:49 +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>
qemu-sockets.c

index a7399aa945a6a4f69e7c069a0d76a769ce09a43e..c526324998b07047daec34b209707e2f817d3935 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;
     }