aboutsummaryrefslogtreecommitdiffstats
path: root/meta-security-compliance/recipes-openscap/scap-security-guide/files/0002-Fixed-the-broken-fix-when-greedy-regex-ate-the-whole.patch
blob: f0c9909c3f859afc3323dfec3a6443b2164478ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
From 28a35d63a0cc6b7beb51c77d93bb30778e6960cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
Date: Mon, 9 Dec 2019 13:41:47 +0100
Subject: [PATCH] Fixed the broken fix, when greedy regex ate the whole file.

We want to match attributes in an XML element, not in the whole file.

Upstream-Status: Backport
[https://github.com/ComplianceAsCode/content/commit/28a35d63a0cc6b7beb51c77d93bb30778e6960cd]

Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
---
 ssg/build_remediations.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ssg/build_remediations.py b/ssg/build_remediations.py
index 13e90f732..edf31c0cf 100644
--- a/ssg/build_remediations.py
+++ b/ssg/build_remediations.py
@@ -57,10 +57,10 @@ def get_available_functions(build_dir):
     with codecs.open(xmlfilepath, "r", encoding="utf-8") as xmlfile:
         filestring = xmlfile.read()
         # This regex looks implementation dependent but we can rely on the element attributes
-        # being present on one line.
+        # being present. Beware, DOTALL means we go through the whole file at once.
         # We can't rely on ElementTree sorting XML attrs in any way since Python 3.7.
         remediation_functions = re.findall(
-            r'<Value.*id=\"function_(\S+)\"',
+            r'<Value[^>]+id=\"function_(\S+)\"',
             filestring, re.DOTALL
         )
 
-- 
2.17.1