Skip to content

Commit 605fe21

Browse files
authored
fix: use strict IPv4 regex in nginx resolver to prevent crash
### Problem The current logic filters IPv6 addresses by counting colons (NF-1 <= 2). However, compressed IPv6 addresses like `fd00::1` contain only two colons, causing them to be incorrectly identified as IPv4. This leads to an invalid `resolver.conf` and Nginx fails to start with: `[emerg] invalid port in resolver "fd00::1"` Solution Replaced the unreliable colon-counting logic with a strict IPv4 regex: ^[0-9]{1,3}(\.[0-9]{1,3}){3}$. This ensures only valid IPv4 addresses are added, maintaining the script's intent to "ignore ipv6 addresses" without crashing Nginx. Impact Fixes container startup failure on hosts with IPv6 ULA or compressed addresses in /etc/resolv.conf.
1 parent b0f0116 commit 605fe21

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • root/etc/s6-overlay/s6-rc.d/init-nginx

root/etc/s6-overlay/s6-rc.d/init-nginx/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ touch /config/nginx/resolver.conf
4747
if ! grep -q 'resolver' /config/nginx/resolver.conf; then
4848
RESOLVERRAW=$(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf)
4949
for i in ${RESOLVERRAW}; do
50-
if [[ "$(awk -F ':' '{print NF-1}' <<<"${i}")" -le 2 ]]; then
50+
if [[ "${i}" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ ]]; then
5151
RESOLVER="${RESOLVER} ${i}"
5252
fi
5353
done

0 commit comments

Comments
 (0)