From: Vincent Bernat Date: Sun, 13 Mar 2016 11:04:06 +0000 (+0100) Subject: interfaces: limit the maximum search depth when applying a VLAN X-Git-Tag: 0.9.2~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e7e6676e05879c364d6d79288f06d4098d2b2775;p=thirdparty%2Flldpd.git interfaces: limit the maximum search depth when applying a VLAN It's now quite easy to hit a bug where we loop over interfaces when trying to find the physical interface associated to a VLAN. Put a maximum depth of 5. --- diff --git a/NEWS b/NEWS index 058a07e6..3022f7e3 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ lldpd (0.9.2) * Change: + Ability to add/remove/replace custom TLV from lldpcli. + LLDP-MED capabilities are displayed differently in lldpcli. + + Limit the maximum depth (5) when trying to apply a VLAN. * Fix: + LLDP-MED POE TLV are now displayed in lldpcli. + Ignore lower link when it is in another namespace. diff --git a/src/daemon/interfaces.c b/src/daemon/interfaces.c index b3f99346..8c18be09 100644 --- a/src/daemon/interfaces.c +++ b/src/daemon/interfaces.c @@ -223,6 +223,7 @@ iface_append_vlan(struct lldpd *cfg, * * @param vlan The VLAN interface (used to get VLAN ID). * @param upper The upper interface we are currently examining. + * @param depth Depth of the stack (avoid infinite recursion) * * Initially, upper == vlan. This function will be called recursively. */ @@ -230,8 +231,16 @@ static void iface_append_vlan_to_lower(struct lldpd *cfg, struct interfaces_device_list *interfaces, struct interfaces_device *vlan, - struct interfaces_device *upper) + struct interfaces_device *upper, + int depth) { + if (depth > 5) { + log_debug("interfaces", + "maximum depth reached when applying VLAN %s (loop?)", + vlan->name); + return; + } + depth++; struct interfaces_device *lower; log_debug("interfaces", "looking to apply VLAN %s to physical interface behind %s", @@ -243,7 +252,8 @@ iface_append_vlan_to_lower(struct lldpd *cfg, vlan->name, upper->name); iface_append_vlan_to_lower(cfg, interfaces, vlan, - upper->lower); + upper->lower, + depth); return; } @@ -262,7 +272,7 @@ iface_append_vlan_to_lower(struct lldpd *cfg, log_debug("interfaces", "VLAN %s on lower interface %s", vlan->name, upper->name); iface_append_vlan_to_lower(cfg, - interfaces, vlan, lower); + interfaces, vlan, lower, depth); } } @@ -283,7 +293,7 @@ interfaces_helper_vlan(struct lldpd *cfg, log_debug("interfaces", "search physical interface for VLAN interface %s", iface->name); iface_append_vlan_to_lower(cfg, interfaces, - iface, iface); + iface, iface, 0); } } #endif