]> git.proxmox.com Git - mirror_qemu.git/commitdiff
can-host-socketcan: Fix crash when 'if' option is not set
authorEduardo Habkost <ehabkost@redhat.com>
Thu, 8 Oct 2020 20:27:12 +0000 (16:27 -0400)
committerEduardo Habkost <ehabkost@redhat.com>
Tue, 13 Oct 2020 19:56:30 +0000 (15:56 -0400)
Fix the following crash:

  $ qemu-system-x86_64 -object can-host-socketcan,id=obj0
  Segmentation fault (core dumped)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Li Qiang <liq3ea@gmail.com>
Acked-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Message-Id: <20201008202713.1416823-3-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
net/can/can_socketcan.c

index 92b1f79385ef23dd94b6fc1a3b94e352e224eb80..4b68f60c6b663afed4e94be80fa6bea7ef566849 100644 (file)
@@ -194,6 +194,11 @@ static void can_host_socketcan_connect(CanHostState *ch, Error **errp)
     struct sockaddr_can addr;
     struct ifreq ifr;
 
+    if (!c->ifname) {
+        error_setg(errp, "'if' property not set");
+        return;
+    }
+
     /* open socket */
     s = qemu_socket(PF_CAN, SOCK_RAW, CAN_RAW);
     if (s < 0) {