summaryrefslogtreecommitdiff
path: root/src/validators
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2025-05-20 14:33:17 +0100
committerGitHub <noreply@github.com>2025-05-20 14:33:17 +0100
commit532a2ef2f9c4fca7589a968c18d0e896912e2a78 (patch)
treed9511287d067410401c83908f7eaf123cc98143c /src/validators
parent72575f9d606201e41ec33fb5ba1fd8642d618c36 (diff)
parent7c9f908f8658126bbe0e9da9dc71be3db45bf940 (diff)
downloadvyos-1x-532a2ef2f9c4fca7589a968c18d0e896912e2a78.tar.gz
vyos-1x-532a2ef2f9c4fca7589a968c18d0e896912e2a78.zip
Merge pull request #4482 from talmakion/bugfix/T5069/permit-compound-regex
policy: T5069: large-community-list regex validator disallows whitespace
Diffstat (limited to 'src/validators')
-rwxr-xr-xsrc/validators/bgp-large-community-list21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/validators/bgp-large-community-list b/src/validators/bgp-large-community-list
index 9ba5b27eb..75276630c 100755
--- a/src/validators/bgp-large-community-list
+++ b/src/validators/bgp-large-community-list
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2021-2023 VyOS maintainers and contributors
+# Copyright (C) 2021-2025 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
@@ -17,18 +17,27 @@
import re
import sys
-pattern = '(.*):(.*):(.*)'
-allowedChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '+', '*', '?', '^', '$', '(', ')', '[', ']', '{', '}', '|', '\\', ':', '-' }
+allowedChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '+', '*', '?', '^', '$', '(', ')', '[', ']', '{', '}', '|', '\\', ':', '-', '_', ' ' }
if __name__ == '__main__':
if len(sys.argv) != 2:
sys.exit(1)
- value = sys.argv[1].split(':')
- if not len(value) == 3:
+ value = sys.argv[1]
+
+ # Require at least one well-formed large-community tuple in the pattern.
+ tmp = value.split(':')
+ if len(tmp) < 3:
+ sys.exit(1)
+
+ # Simple guard against invalid community & 1003.2 pattern chars
+ if not set(value).issubset(allowedChars):
sys.exit(1)
- if not (re.match(pattern, sys.argv[1]) and set(sys.argv[1]).issubset(allowedChars)):
+ # Don't feed FRR badly formed regex
+ try:
+ re.compile(value)
+ except re.error:
sys.exit(1)
sys.exit(0)