From 6e2b9f72546b045a122fd8d15ddd800e69a95b56 Mon Sep 17 00:00:00 2001 From: buildplan Date: Mon, 17 Nov 2025 11:42:32 +0000 Subject: [PATCH] improve ip validation --- du_setup.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/du_setup.sh b/du_setup.sh index 0316b71..9e0ada2 100644 --- a/du_setup.sh +++ b/du_setup.sh @@ -2559,7 +2559,6 @@ validate_ip_or_cidr() { local input="$1" # IPv4 address (simple check) if [[ "$input" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then - # Validate octets are <= 255 local -a octets IFS='.' read -ra octets <<< "$input" for octet in "${octets[@]}"; do @@ -2573,7 +2572,6 @@ validate_ip_or_cidr() { if [[ "$input" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}$ ]]; then local ip="${input%/*}" local cidr="${input##*/}" - # Validate IP part local -a octets IFS='.' read -ra octets <<< "$ip" for octet in "${octets[@]}"; do @@ -2581,18 +2579,17 @@ validate_ip_or_cidr() { return 1 fi done - # Validate CIDR is 0-32 if [[ "$cidr" -ge 0 && "$cidr" -le 32 ]]; then return 0 fi return 1 fi # IPv6 address (basic check) - if [[ "$input" =~ ^([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}$ ]]; then + if [[ "$input" =~ ^[0-9a-fA-F:]+$ && "$input" == *":"* && "$input" != *"/"* ]]; then return 0 fi - # IPv6 CIDR (e.g., 2001:db8::/32) - if [[ "$input" =~ ^([0-9a-fA-F]{0,4}:){2,7}[0-9a-fA-F]{0,4}/[0-9]{1,3}$ ]]; then + # IPv6 CIDR (permissive check, allows compressed ::) + if [[ "$input" =~ ^[0-9a-fA-F:]+/[0-9]{1,3}$ && "$input" == *":"* ]]; then local cidr="${input##*/}" if [[ "$cidr" -ge 0 && "$cidr" -le 128 ]]; then return 0