Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion etc/rc.d/rc.inet1.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,27 @@ unzero(){
# function to remove leading zeros in IPv6 address
unzero6(){
local A M Q
if [[ $1 == "::" ]]; then
printf "::"
return 0
fi
# Replace first :: with sentinel
A=${1/::/:-:}
echo -n $(for Q in ${A//:/ }; do [[ $Q != - ]] && printf "$M%x" "0x$Q" || printf ":"; M=:; done)
M=
for Q in ${A//:/ }; do
if [[ $Q != - ]]; then
# Validate hex (1-4 digits)
[[ $Q =~ ^[0-9A-Fa-f]{1,4}$ ]] || return 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Search for the function and its usages
rg -n -C3 'unzero6' etc/rc.d/rc.inet1.conf

Repository: unraid/webgui

Length of output: 200


🏁 Script executed:

# Also search for unzero6 calls throughout the codebase
rg -n 'unzero6' --type sh

Repository: unraid/webgui

Length of output: 39


🏁 Script executed:

# Get more context around line 47 in the file
sed -n '30,70p' etc/rc.d/rc.inet1.conf | cat -n

Repository: unraid/webgui

Length of output: 1365


🏁 Script executed:

# Search for calls to unzero6 anywhere in the codebase
rg -n 'unzero6' -A 2 -B 2

Repository: unraid/webgui

Length of output: 2421


🏁 Script executed:

# Also search for patterns that might invoke unzero6
rg -n '\$\(.*unzero6' -A 2 -B 2

Repository: unraid/webgui

Length of output: 1979


🏁 Script executed:

# Get more context around each call site to verify error handling
sed -n '410,415p' etc/rc.d/rc.inet1 | cat -n

Repository: unraid/webgui

Length of output: 459


🏁 Script executed:

sed -n '505,515p' etc/rc.d/rc.inet1 | cat -n

Repository: unraid/webgui

Length of output: 878


🏁 Script executed:

sed -n '645,650p' etc/rc.d/rc.inet1 | cat -n

Repository: unraid/webgui

Length of output: 360


Add error checking at all call sites for the return value of unzero6.

The function returns 1 when encountering invalid hex components. Currently, none of the 7 callers check this return value, resulting in silent failures when processing malformed IPv6 addresses:

  • IPv6 address configuration (line 413)
  • DNS server entries (lines 510-513)
  • Route configuration (lines 647-648)
  • Wireless interface setup (rc.wireless:157)

When unzero6 fails, it outputs nothing, leaving downstream commands with empty or incomplete strings that fail silently.

🤖 Prompt for AI Agents
In `@etc/rc.d/rc.inet1.conf` at line 47, unzero6 can return 1 on invalid hex
components but none of its callers check this, causing silent failures; update
every call site of unzero6 (the IPv6 address configuration handling, the DNS
server entry processing, the route configuration logic, and the rc.wireless
setup calls) to test its return status, and on non‑zero either log an error and
abort the higher‑level operation (return failure) or skip the malformed entry
rather than using the empty output — ensure you reference the unzero6 invocation
and the variable capturing its output in each caller and early‑exit or continue
appropriately to avoid feeding empty strings into downstream commands.

printf "%s%x" "$M" "0x$Q"
else
# Restore a single colon for sentinel
printf ":"
fi
M=:
done

# Handle trailing :: (but avoid adding for the special case "::")
[[ $1 == *:: && $1 != "::" ]] && printf ":"
}

# Bergware - use associative format for multi-dimensional arrays
Expand Down
Loading