From: Thomas Huth Date: Fri, 16 Mar 2018 09:51:29 +0000 (+0100) Subject: hw/net/can: Fix segfaults when using the devices without bus X-Git-Tag: v2.12.0-rc1~10^2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=089eac81e1d34d202471c0a023284f47f4c5f00e;p=thirdparty%2Fqemu.git hw/net/can: Fix segfaults when using the devices without bus The CAN devices can currently be used to crash QEMU, e.g.: $ x86_64-softmmu/qemu-system-x86_64 -device kvaser_pci Segmentation fault (core dumped) So we've got to add a proper check here that the corresponding bus is available. Signed-off-by: Thomas Huth Message-Id: <1521193892-15552-2-git-send-email-thuth@redhat.com> Signed-off-by: Paolo Bonzini --- diff --git a/hw/net/can/can_sja1000.c b/hw/net/can/can_sja1000.c index 629323312cf..9a85038c8ad 100644 --- a/hw/net/can/can_sja1000.c +++ b/hw/net/can/can_sja1000.c @@ -866,6 +866,10 @@ int can_sja_connect_to_bus(CanSJA1000State *s, CanBusState *bus) { s->bus_client.info = &can_sja_bus_client_info; + if (!bus) { + return -EINVAL; + } + if (can_bus_insert_client(bus, &s->bus_client) < 0) { return -1; }