summaryrefslogtreecommitdiff
path: root/src/validators/port-range
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2022-01-10 22:31:55 +0100
committerGitHub <noreply@github.com>2022-01-10 22:31:55 +0100
commit465939d9c9b413c7033c8833cbb4ebc30b9bcf66 (patch)
tree361079ff54ed2c5516cc86a8644e98ce629d2a73 /src/validators/port-range
parentfd1b1ff19b0ff852d796e979ab3b596651686f2f (diff)
parent0a0e7d789e7e482b65cbca47bff1dcb427891a88 (diff)
downloadvyos-1x-465939d9c9b413c7033c8833cbb4ebc30b9bcf66.tar.gz
vyos-1x-465939d9c9b413c7033c8833cbb4ebc30b9bcf66.zip
Merge pull request #1152 from sarthurdev/firewall_validators
firewall: validators: T4148: Improve validators and firewall validator usage
Diffstat (limited to 'src/validators/port-range')
-rwxr-xr-xsrc/validators/port-range19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/validators/port-range b/src/validators/port-range
index abf0b09d5..657a21e20 100755
--- a/src/validators/port-range
+++ b/src/validators/port-range
@@ -3,16 +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):
- sys.exit(1)
- else:
- if int(port_range) not in range(1, 65535):
- 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)