]> git.ipfire.org Git - thirdparty/suricata-update.git/commitdiff
misc: fix (more) escape warnings in re patterns
authorJason Ish <jason.ish@oisf.net>
Fri, 16 Feb 2024 16:55:16 +0000 (10:55 -0600)
committerJason Ish <jason.ish@oisf.net>
Fri, 16 Feb 2024 16:55:16 +0000 (10:55 -0600)
suricata/update/engine.py
suricata/update/matchers.py
suricata/update/osinfo.py
suricata/update/rule.py

index c57da82ba4586e0947e923ba734c3bf2d6055e64..22ad9b3ccbf47f39edf77dda8283e37b996cf925 100644 (file)
@@ -135,7 +135,7 @@ def get_path(program="suricata"):
     return None
 
 def parse_version(buf):
-    m = re.search("((\d+)\.(\d+)(\.(\d+))?([\w\-]+)?)", str(buf).strip())
+    m = re.search(r"((\d+)\.(\d+)(\.(\d+))?([\w\-]+)?)", str(buf).strip())
     if m:
         full = m.group(1)
         major = int(m.group(2))
index e886c79784e8b56b2f52293fc7dbf7235bdda54b..56a9e294e038a60ecd3084b19751fb4d4c8b4cde 100644 (file)
@@ -251,7 +251,7 @@ class ModifyRuleFilter(object):
         pattern = re.compile(a)
 
         # Convert Oinkmaster backticks to Python.
-        b = re.sub("\$\{(\d+)\}", "\\\\\\1", b)
+        b = re.sub(r"\$\{(\d+)\}", "\\\\\\1", b)
 
         return cls(matcher, pattern, b)
 
@@ -269,7 +269,7 @@ class DropRuleFilter(object):
 
     def run(self, rule):
         drop_rule = suricata.update.rule.parse(re.sub(
-            "^\w+", "drop", rule.raw))
+            r"^\w+", "drop", rule.raw))
         drop_rule.enabled = rule.enabled
         return drop_rule
 
@@ -284,7 +284,7 @@ class AddMetadataFilter(object):
         return self.matcher.match(rule)
 
     def run(self, rule):
-        new_rule_string = re.sub(";\s*\)$", "; metadata: {} {};)".format(self.key, self.val), rule.format())
+        new_rule_string = re.sub(r";\s*\)$", "; metadata: {} {};)".format(self.key, self.val), rule.format())
         new_rule = suricata.update.rule.parse(new_rule_string, rule.group)
         if not new_rule:
             logger.error("Rule is not valid after adding metadata: [{}]: {}".format(rule.idstr, new_rule_string))
index 82816bc89d42ee760f8203cfd9038cb0c83e15c2..c3e417b46b620300a368cb5b83fed8b119131e2d 100644 (file)
@@ -27,7 +27,7 @@ def parse_os_release(filename="/etc/os-release"):
     with open(filename) as fileobj:
         for line in fileobj:
             line = line.strip()
-            m = re.match("^(\w+)=\"?(.*?)\"?$", line)
+            m = re.match(r"^(\w+)=\"?(.*?)\"?$", line)
             if m:
                 os_release[m.group(1)] = m.group(2)
     return os_release
index 42c673e92d31eefa89fabae91a4d962bc9438e7d..169af6ce1a5a52cba9d90da8197b29cc234b9fa6 100644 (file)
@@ -436,4 +436,4 @@ def parse_var_names(var):
     """ Parse out the variable names from a string. """
     if var is None:
         return []
-    return re.findall("\$([\w_]+)", var)
+    return re.findall(r"\$([\w_]+)", var)