luci-mod-status: protect against infinite recursion in port status
authorJo-Philipp Wich <jo@mein.io>
Wed, 25 Oct 2023 21:16:13 +0000 (23:16 +0200)
committerJo-Philipp Wich <jo@mein.io>
Wed, 25 Oct 2023 21:16:13 +0000 (23:16 +0200)
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 <jo@mein.io>
modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/29_ports.js

index 1351ab935a55c206d75f0927ed7e154987cf3d48..9ea5555deb40de528108253a5d0e7de19e9e9719 100644 (file)
@@ -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);
 }