summaryrefslogtreecommitdiff
path: root/src/validators
diff options
context:
space:
mode:
authorsarthurdev <965089+sarthurdev@users.noreply.github.com>2022-01-09 23:45:04 +0100
committersarthurdev <965089+sarthurdev@users.noreply.github.com>2022-01-10 21:18:03 +0100
commit0a0e7d789e7e482b65cbca47bff1dcb427891a88 (patch)
treed8f894e3d4d82f694cb5183bde1c557a1a5584e8 /src/validators
parentda370b63b266254d9a7a7ae15274a9a70bcf5417 (diff)
downloadvyos-1x-0a0e7d789e7e482b65cbca47bff1dcb427891a88.tar.gz
vyos-1x-0a0e7d789e7e482b65cbca47bff1dcb427891a88.zip
validators: Stricter checking on port-range validator
Diffstat (limited to 'src/validators')
-rwxr-xr-xsrc/validators/port-range21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/validators/port-range b/src/validators/port-range
index 6e68c8733..657a21e20 100755
--- a/src/validators/port-range
+++ b/src/validators/port-range
@@ -3,18 +3,21 @@
import sys
import re
+def error(port_range):
+ print(f'Error: {port_range} is not a valid port or port range')
+ sys.exit(1)
+
if __name__ == '__main__':
if len(sys.argv)>1:
port_range = sys.argv[1]
- if re.search('[0-9]{1,5}-[0-9]{1,5}', port_range):
- for tmp in port_range.split('-'):
- if int(tmp) not in range(1, 65535):
- print(f'Error: {port_range} is not a valid port range')
- sys.exit(1)
- else:
- if int(port_range) not in range(1, 65535):
- print(f'Error: {port_range} is not a valid port')
- sys.exit(1)
+ if re.match('^[0-9]{1,5}-[0-9]{1,5}$', port_range):
+ port_1, port_2 = port_range.split('-')
+ if int(port_1) not in range(1, 65535) or int(port_2) not in range(1, 65535):
+ error(port_range)
+ if int(port_1) > int(port_2):
+ error(port_range)
+ elif not port_range.isnumeric() or int(port_range) not in range(1, 65535):
+ error(port_range)
else:
sys.exit(2)