can-host: Fix crash when 'canbus' property is not set

Providing the 'if' property, but not 'canbus' segfaults like this:

 #0  0x0000555555b0f14d in can_bus_insert_client (bus=0x0, client=0x555556aa9af0) at ../net/can/can_core.c:88
 #1  0x00005555559c3803 in can_host_connect (ch=0x555556aa9ac0, errp=0x7fffffffd568) at ../net/can/can_host.c:62
 #2  0x00005555559c386a in can_host_complete (uc=0x555556aa9ac0, errp=0x7fffffffd568) at ../net/can/can_host.c:72
 #3  0x0000555555d52de9 in user_creatable_complete (uc=0x555556aa9ac0, errp=0x7fffffffd5c8) at ../qom/object_interfaces.c:23

Add the missing NULL check.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20201130105615.21799-5-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Kevin Wolf 2020-11-30 11:56:15 +01:00
parent f0947dc694
commit 7cc25f6c9b

View file

@ -53,6 +53,11 @@ static void can_host_connect(CanHostState *ch, Error **errp)
CanHostClass *chc = CAN_HOST_GET_CLASS(ch);
Error *local_err = NULL;
if (ch->bus == NULL) {
error_setg(errp, "'canbus' property not set");
return;
}
chc->connect(ch, &local_err);
if (local_err) {
error_propagate(errp, local_err);