From: Josef Schlehofer Date: Thu, 6 Aug 2026 10:42:19 +0000 (+0200) Subject: alfred: handle unreadable files in bat-hosts.lua X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=2312f86f7e7b0eb7029596a04cc878ebe648b921;p=openwrt-packages.git alfred: handle unreadable files in bat-hosts.lua get_interface_address() calls io.open() and dereferences the result without checking it. /sys/class/net does not contain interfaces only: with the bonding module loaded it also holds the plain file bonding_masters, which the `ls -1` in get_interfaces_names() returns and which has no address below it. io.open() then returns nil and the script dies with "attempt to index a nil value", so no bat-hosts data is published at all on such a node. Return nil when the file cannot be opened and skip those entries in the caller, which would otherwise index the interface table with nil. get_hostname() gets the same guard. Reported-by: openwrt-ai[bot] Signed-off-by: Josef Schlehofer Co-authored-by: Claude Fable 5 --- diff --git a/net/alfred/files/bat-hosts.lua b/net/alfred/files/bat-hosts.lua index f9fe58687..c9b561939 100644 --- a/net/alfred/files/bat-hosts.lua +++ b/net/alfred/files/bat-hosts.lua @@ -4,6 +4,7 @@ local type_id = 64 -- bat-hosts function get_hostname() local hostfile = io.open("/proc/sys/kernel/hostname", "r") + if not hostfile then return nil end local ret_string = hostfile:read() hostfile:close() return ret_string @@ -20,7 +21,10 @@ function get_interfaces_names() end function get_interface_address(name) + -- /sys/class/net also contains plain files, e.g. bonding_masters + -- once the bonding module is loaded, which have no address below them local addressfile = io.open("/sys/class/net/"..name.."/address", "r") + if not addressfile then return nil end local ret_string = addressfile:read() addressfile:close() return ret_string @@ -37,7 +41,7 @@ local function generate_bat_hosts() for n, i in ipairs(get_interfaces_names()) do local address = get_interface_address(i) - if not ifaces[address] then ifaces[address] = i end + if address and not ifaces[address] then ifaces[address] = i end end for mac, iname in pairs(ifaces) do