summaryrefslogtreecommitdiff
path: root/interface.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2016-08-11 19:36:09 +0200
committerFelix Fietkau <nbd@nbd.name>2016-08-11 19:36:12 +0200
commitc8a5f1ae361ab61192be6085c29d977eb73a05f5 (patch)
tree65918e9f440b766a29b4d68e80bf8c4dc59691fb /interface.c
parentcec1ce296eede81dc62628fce33b8cc216727b17 (diff)
downloadnetifd-c8a5f1ae361ab61192be6085c29d977eb73a05f5.tar.gz
Prevent premature device free in interface_claim_device
interface_set_device_config can trigger a device free (for example if the device is here only present in a bridge), which renders dev invalid and leads to segfault. Add a lock to prevent this and clean-up the code for readability. Signed-off-by: Gino Peeters <peeters.gino@gmail.com> Signed-off-by: Hans Dedecker <dedeckeh@gmail.com> Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'interface.c')
-rw-r--r--interface.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/interface.c b/interface.c
index 0b9893c..71e2ecc 100644
--- a/interface.c
+++ b/interface.c
@@ -586,6 +586,8 @@ interface_claim_device(struct interface *iface)
if (iface->parent_iface.iface)
interface_remove_user(&iface->parent_iface);
+ device_lock();
+
if (iface->parent_ifname) {
parent = vlist_find(&interfaces, iface->parent_ifname, parent, node);
iface->parent_iface.cb = interface_alias_cb;
@@ -601,6 +603,8 @@ interface_claim_device(struct interface *iface)
if (dev)
interface_set_main_dev(iface, dev);
+ device_unlock();
+
if (iface->proto_handler->flags & PROTO_FLAG_INIT_AVAILABLE)
interface_set_available(iface, true);
}