interface: fix use-after-free bug when rewriting resolv.conf
authorFelix Fietkau <nbd@nbd.name>
Thu, 25 Aug 2022 19:09:24 +0000 (21:09 +0200)
committerFelix Fietkau <nbd@nbd.name>
Thu, 25 Aug 2022 19:13:35 +0000 (21:13 +0200)
After the call to interface_handle_config_change, the iface pointer will no
longer be valid if the interface has been deleted from the config

Signed-off-by: Felix Fietkau <nbd@nbd.name>
interface.c

index 255ce84950385bf586e284b14b6727ec4d64d9c1..89654f952c15b571e866dbcf2b84773c63a84d6a 100644 (file)
@@ -771,12 +771,13 @@ interface_proto_event_cb(struct interface_proto_state *state, enum interface_pro
 
                netifd_log_message(L_NOTICE, "Interface '%s' is now down\n", iface->name);
                mark_interface_down(iface);
+               interface_write_resolv_conf(iface->jail);
                if (iface->main_dev.dev)
                        device_release(&iface->main_dev);
                if (iface->l3_dev.dev)
                        device_remove_user(&iface->l3_dev);
                interface_handle_config_change(iface);
-               break;
+               return;
        case IFPEV_LINK_LOST:
                if (iface->state != IFS_UP)
                        return;