From bbfdbf5f76ac0cdb85c9ccb5361bbfd8a0168e93 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 14 Jul 2021 18:18:02 +0200 Subject: [PATCH] device/dhcp: avoid crash by not starting DHCPv6 client without ifindex https://bugzilla.redhat.com/show_bug.cgi?id=1973199 (cherry picked from commit 85f53f43e973a31b5c04f65038c4ce19b586553a) --- src/core/devices/nm-device.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index b82e2567a8..87e71ad328 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -9968,6 +9968,7 @@ dhcp6_start_with_link_ready(NMDevice *self, NMConnection *connection) gboolean iaid_explicit; NMSettingConnection * s_con; const NMPlatformIP6Address *ll_addr = NULL; + int ip_ifindex; g_return_val_if_fail(connection, FALSE); @@ -9987,7 +9988,13 @@ dhcp6_start_with_link_ready(NMDevice *self, NMConnection *connection) return FALSE; } - pllink = nm_platform_link_get(nm_device_get_platform(self), nm_device_get_ip_ifindex(self)); + ip_ifindex = nm_device_get_ip_ifindex(self); + if (ip_ifindex <= 0) { + _LOGD(LOGD_DHCP6, "can't start DHCPv6: interface is gone"); + return FALSE; + } + + pllink = nm_platform_link_get(nm_device_get_platform(self), ip_ifindex); if (pllink) hwaddr = nmp_link_address_get_as_bytes(&pllink->l_address); @@ -9998,7 +10005,7 @@ dhcp6_start_with_link_ready(NMDevice *self, NMConnection *connection) nm_dhcp_manager_get(), nm_device_get_multi_index(self), nm_device_get_ip_iface(self), - nm_device_get_ip_ifindex(self), + ip_ifindex, &ll_addr->address, nm_connection_get_uuid(connection), nm_device_get_route_table(self, AF_INET6),