Skip to contentSkip to conversation

qemu-kvm: avoid strlen of NULL pointer

PATCH Applied Jens Osterkamp 2 participants 2 messages Apr 12, 2010 – May 18, 2010

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 qemu-kvm: avoid strlen of NULL pointer

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.

---
 qemu-sockets.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
qemu-sockets.c +2 -1
index 23c3def..87a79e5 100644
@@ -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;
     }
Signature · 1 line
1.5.6.3
#1 lore raw
Quoted 7 lines · Jens Osterkamp

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.

Thanks, applied.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net