aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2022-01-25 12:40:48 -0500
committerJake Hunsaker <jhunsake@redhat.com>2022-02-07 08:38:23 -0500
commit6ced41538652895ca7ff828547179c0b28488716 (patch)
treecfebc60434d6dd951e4d6d71acf9ac8b6425b67e
parent6b7556cb61fe809d998202bdda3d0a7302b8c74a (diff)
downloadsos-6ced41538652895ca7ff828547179c0b28488716.tar.gz
[mac_parser] Avoid substring matches with look-behinds
This commit adds a negative look-behind to the regex patterns for mac addresses so we avoid matching substrings from both non-mac-address strings, certain ipv6 address strings, and longer strings of hextets that we could potentially match a substring of. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/cleaner/parsers/mac_parser.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/sos/cleaner/parsers/mac_parser.py b/sos/cleaner/parsers/mac_parser.py
index 763df034..b7ed2bae 100644
--- a/sos/cleaner/parsers/mac_parser.py
+++ b/sos/cleaner/parsers/mac_parser.py
@@ -13,17 +13,25 @@ from sos.cleaner.mappings.mac_map import SoSMacMap
import re
+# aa:bb:cc:fe:ff:dd:ee:ff
+IPV6_REG_8HEX = (r'((?<!([0-9a-fA-F]:)|::)([^:|-])?([0-9a-fA-F]{2}(:|-)){7}'
+ r'[0-9a-fA-F]{2}(\s|$))')
+# aabb:ccee:ddee:ffaa
+IPV6_REG_4HEX = (r'((?<!([0-9a-fA-F]:)|::)(([^:\-]?[0-9a-fA-F]{4}(:|-)){3}'
+ r'[0-9a-fA-F]{4}(\s|$)))')
+# aa:bb:cc:dd:ee:ff avoiding ipv6 substring matches
+IPV4_REG = (r'((?<!([0-9a-fA-F]:)|::)(([^:\-])?([0-9a-fA-F]{2}([:-])){5}'
+ r'([0-9a-fA-F]){2}(\s|$)))')
+
class SoSMacParser(SoSCleanerParser):
"""Handles parsing for MAC addresses"""
name = 'MAC Parser'
regex_patterns = [
- # IPv6
- r'(([^:|-])?([0-9a-fA-F]{2}(:|-)){7}[0-9a-fA-F]{2}(\s|$))',
- r'(([^:|-])([0-9a-fA-F]{4}(:|-)){3}[0-9a-fA-F]{4}(\s|$))',
- # IPv4, avoiding matching a substring within IPv6 addresses
- r'(([^:|-])?([0-9a-fA-F]{2}([:-])){5}([0-9a-fA-F]){2}(.)?(\s|$|\W))'
+ IPV6_REG_8HEX,
+ IPV6_REG_4HEX,
+ IPV4_REG
]
obfuscated_patterns = (
'53:4f:53',