Explorar o código

ip format validator fix for cidr

Serghey Rodin %!s(int64=9) %!d(string=hai) anos
pai
achega
1ed58a9efc
Modificáronse 1 ficheiros con 3 adicións e 4 borrados
  1. 3 4
      func/main.sh

+ 3 - 4
func/main.sh

@@ -97,7 +97,7 @@ check_result() {
 # Argument list checker
 check_args() {
     if [ "$1" -gt "$2" ]; then
-        echo "Usage: $SCRIPT $3"
+        echo "Usage: $(basename $0) $3"
         check_result $E_ARGS "not enought arguments" >/dev/null
     fi
 }
@@ -501,15 +501,14 @@ is_alias_format_valid() {
 is_ip_format_valid() {
     object_name=${2-ip}
     ip_regex='([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])'
-    ip_clean=$(echo "${1%/[0-9][0-9]}")
-    ip_clean=$(echo "${1%/[0-9]}")
+    ip_clean=$(echo "${1%/*}")
     if ! [[ $ip_clean =~ ^$ip_regex\.$ip_regex\.$ip_regex\.$ip_regex$ ]]; then
         check_result $E_INVALID "invalid $object_name format :: $1"
     fi
     if [ $1 != "$ip_clean" ]; then
         ip_cidr="$ip_clean/"
         ip_cidr=$(echo "${1#$ip_cidr}")
-        if [[ "$ip_cidr" -gt 32 ]]; then
+        if [[ "$ip_cidr" -gt 32 ]] || [[ "$ip_cidr" =~ [:alnum:] ]]; then
             check_result $E_INVALID "invalid $object_name format :: $1"
         fi
     fi