diff mbox

[1/1] virtio-serial: fix segfault on NULL port names

Message ID 36afc0db03021aa7259dc76107e8f5bb4ae61e10.1425459836.git.amit.shah@redhat.com
State New
Headers show

Commit Message

Amit Shah March 4, 2015, 9:03 a.m. UTC
Commit d0a0bfe6729ef6044d76ea49fafa07e29fa598bd added checks for port
names, but didn't add a check to ensure port->name is non-NULL.  This
results in a SIGSEGV.

https://bugzilla.redhat.com/show_bug.cgi?id=1192775

Reported-by: vivian zhang <vivianzhang@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 hw/char/virtio-serial-bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Markus Armbruster March 4, 2015, 10:49 a.m. UTC | #1
Amit Shah <amit.shah@redhat.com> writes:

> Commit d0a0bfe6729ef6044d76ea49fafa07e29fa598bd added checks for port
> names, but didn't add a check to ensure port->name is non-NULL.  This
> results in a SIGSEGV.
>
> https://bugzilla.redhat.com/show_bug.cgi?id=1192775
>
> Reported-by: vivian zhang <vivianzhang@redhat.com>
> Signed-off-by: Amit Shah <amit.shah@redhat.com>

Reviewed-by: Markus Armbruster <armbru@redhat.com>
diff mbox

Patch

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 47fbb34..acd1173 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -64,7 +64,7 @@  static VirtIOSerialPort *find_port_by_name(char *name)
         VirtIOSerialPort *port;
 
         QTAILQ_FOREACH(port, &vser->ports, next) {
-            if (!strcmp(port->name, name)) {
+            if (port->name && !strcmp(port->name, name)) {
                 return port;
             }
         }