Skip to content

Commit 1ed58a9

Browse files
author
Serghey Rodin
committed
ip format validator fix for cidr
1 parent 136cc17 commit 1ed58a9

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

func/main.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ check_result() {
9797
# Argument list checker
9898
check_args() {
9999
if [ "$1" -gt "$2" ]; then
100-
echo "Usage: $SCRIPT $3"
100+
echo "Usage: $(basename $0) $3"
101101
check_result $E_ARGS "not enought arguments" >/dev/null
102102
fi
103103
}
@@ -501,15 +501,14 @@ is_alias_format_valid() {
501501
is_ip_format_valid() {
502502
object_name=${2-ip}
503503
ip_regex='([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])'
504-
ip_clean=$(echo "${1%/[0-9][0-9]}")
505-
ip_clean=$(echo "${1%/[0-9]}")
504+
ip_clean=$(echo "${1%/*}")
506505
if ! [[ $ip_clean =~ ^$ip_regex\.$ip_regex\.$ip_regex\.$ip_regex$ ]]; then
507506
check_result $E_INVALID "invalid $object_name format :: $1"
508507
fi
509508
if [ $1 != "$ip_clean" ]; then
510509
ip_cidr="$ip_clean/"
511510
ip_cidr=$(echo "${1#$ip_cidr}")
512-
if [[ "$ip_cidr" -gt 32 ]]; then
511+
if [[ "$ip_cidr" -gt 32 ]] || [[ "$ip_cidr" =~ [:alnum:] ]]; then
513512
check_result $E_INVALID "invalid $object_name format :: $1"
514513
fi
515514
fi

0 commit comments

Comments
 (0)