Patchwork [v2] qemu-kvm: avoid strlen of NULL pointer

login
register
mail settings
Submitter Jens Osterkamp
Date April 12, 2010, 8:51 a.m.
Message ID <201004121051.02057.jens@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/49958/
State New
Headers show

Comments

Jens Osterkamp - April 12, 2010, 8:51 a.m.
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>
---
 qemu-sockets.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
Aurelien Jarno - May 18, 2010, 5:48 p.m.
On Mon, Apr 12, 2010 at 10:51:01AM +0200, Jens Osterkamp wrote:
> 
> 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>

Thanks, applied.

Patch

diff --git a/qemu-sockets.c b/qemu-sockets.c
index 23c3def..87a79e5 100644
--- a/qemu-sockets.c
+++ b/qemu-sockets.c
@@ -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, "port") == NULL) ||
+	(qemu_opt_get(opts, "host") == NULL)) {
         fprintf(stderr, "%s: host and/or port not specified\n", __FUNCTION__);
         return -1;
     }