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 <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2023-10-25 23:16:13 +02:00
parent 575ce5512d
commit 25dd8934f1

View 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);
}