From f875367413201aaaf25c7897eb9fd2a206c58f55 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 25 Oct 2023 23:16:13 +0200 Subject: [PATCH] luci-mod-status: protect against infinite recursion in port status When attempting to resolve VLAN devices, protect against potential deep recursion due to invalid bridge configs referencing themselves. Fixes: #6648 Signed-off-by: Jo-Philipp Wich (cherry picked from commit 25dd8934f18a6cebfca1adb8a0d4b5d0bed73145) --- .../resources/view/status/include/29_ports.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/29_ports.js b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/29_ports.js index 1351ab935a..9ea5555deb 100644 --- a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/29_ports.js +++ b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/29_ports.js @@ -138,15 +138,24 @@ function buildVLANMappings(mapping) } } -function resolveVLANPorts(ifname, mapping) +function resolveVLANPorts(ifname, mapping, seen) { var ports = []; - if (mapping[ifname]) - for (var i = 0; i < mapping[ifname].length; i++) - ports.push.apply(ports, resolveVLANPorts(mapping[ifname][i], mapping)); - else + if (!seen) + seen = {}; + + if (mapping[ifname]) { + for (var i = 0; i < mapping[ifname].length; i++) { + if (!seen[mapping[ifname][i]]) { + seen[mapping[ifname][i]] = true; + ports.push.apply(ports, resolveVLANPorts(mapping[ifname][i], mapping, seen)); + } + } + } + else { ports.push(ifname); + } return ports.sort(L.naturalCompare); } -- 2.30.2