From 7d43a3d488add8c54ded952ab0e4c94d2587e29d Mon Sep 17 00:00:00 2001 From: Wesley Ray Date: Sun, 29 Jun 2025 10:45:42 -0400 Subject: [PATCH] fixed regular expression in live nameserver parsing function --- skyweave/utils.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/skyweave/utils.lua b/skyweave/utils.lua index 1a4291a..f915c86 100755 --- a/skyweave/utils.lua +++ b/skyweave/utils.lua @@ -162,29 +162,32 @@ function utils.get_live_interface_info(interface_name) return nil end --- Moved from original main script function utils.get_live_dns_servers_from_resolv(logical_interface_name) local dns_servers = {} local search_domains = {} - -- Ensure logical_interface_name is somewhat safe before using in string matching, - -- though it's typically from internal config. + if not logical_interface_name or not logical_interface_name:match("^[a-zA-Z0-9_%-]+$") then - return dns_servers, search_domains -- Invalid interface name format + return dns_servers, search_domains end local file = io.open("/tmp/resolv.conf.auto", "r") if not file then return dns_servers, search_domains end local in_target_section = false - local section_start_pattern_str = "# Interface " .. logical_interface_name + -- It looks for the logical_interface_name followed by an optional underscore and digits (e.g., "_4"), + -- and then the end of the line. This prevents "wan" from incorrectly matching "wan_lte_". + local section_start_pattern = "^%s*# Interface%s+" .. logical_interface_name .. "(_%d+)?%s*$" for line in file:lines() do if not in_target_section then - if line:match("^%s*" .. section_start_pattern_str:gsub("%%", "%%%%") .. "%s*$") then -- Escape % for string pattern + -- We now use the more precise pattern to find our starting point. + if line:match(section_start_pattern) then in_target_section = true end else - if line:match("^%s*# Interface ") and not line:match("^%s*" .. section_start_pattern_str:gsub("%%", "%%%%") .. "%s*$") then + -- The end-of-section logic is now also hardened. We break if we find a new + -- "# Interface" line that does NOT match our precise pattern. + if line:match("^%s*# Interface") and not line:match(section_start_pattern) then break end