Blame SOURCES/openscap-1.3.4-fix-no-more-recursion.patch

4def80
From c8fc880a672afbfdbd384dc6afa4b7fbdd666b73 Mon Sep 17 00:00:00 2001
4def80
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
4def80
Date: Wed, 27 May 2020 10:38:56 +0200
4def80
Subject: [PATCH 1/3] Add a regression test for RHBZ#1686370
4def80
4def80
There is a non-optimal behavior of file probe. It happens when file path
4def80
is specified using a variable with 2 values with `operation="equals"`
4def80
and `var_check="all"`. The probe recurses into a file system tree even
4def80
if it's obvious that it won't find any match. If one of values is a big
4def80
tree (for example `/`) it eventually runs out of memory and crashes. The
4def80
OVAL doesn't make sense because it's impossible that a single file would
4def80
have 2 different paths. But despite that it's a valid OVAL document.
4def80
The test is expected to fail because the bug hasn't been fixed.
4def80
---
4def80
 tests/probes/file/CMakeLists.txt              |  1 +
4def80
 .../test_probes_file_multiple_file_paths.sh   | 39 +++++++++++++++++
4def80
 .../test_probes_file_multiple_file_paths.xml  | 42 +++++++++++++++++++
4def80
 3 files changed, 82 insertions(+)
4def80
 create mode 100755 tests/probes/file/test_probes_file_multiple_file_paths.sh
4def80
 create mode 100644 tests/probes/file/test_probes_file_multiple_file_paths.xml
4def80
4def80
diff --git a/tests/probes/file/CMakeLists.txt b/tests/probes/file/CMakeLists.txt
4def80
index 12718603f..35b4c1169 100644
4def80
--- a/tests/probes/file/CMakeLists.txt
4def80
+++ b/tests/probes/file/CMakeLists.txt
4def80
@@ -1,3 +1,4 @@
4def80
 if(ENABLE_PROBES_UNIX)
4def80
 	add_oscap_test("test_probes_file.sh")
4def80
+	add_oscap_test("test_probes_file_multiple_file_paths.sh")
4def80
 endif()
4def80
diff --git a/tests/probes/file/test_probes_file_multiple_file_paths.sh b/tests/probes/file/test_probes_file_multiple_file_paths.sh
4def80
new file mode 100755
4def80
index 000000000..1cececbb0
4def80
--- /dev/null
4def80
+++ b/tests/probes/file/test_probes_file_multiple_file_paths.sh
4def80
@@ -0,0 +1,39 @@
4def80
+#!/bin/bash
4def80
+
4def80
+set -e -o pipefail
4def80
+
4def80
+. $builddir/tests/test_common.sh
4def80
+
4def80
+probecheck "file" || exit 255
4def80
+which strace || exit 255
4def80
+
4def80
+function check_strace_output {
4def80
+	strace_log="$1"
4def80
+	grep -q "/tmp/numbers/1" $strace_log && return 1
4def80
+	grep -q "/tmp/numbers/1/2" $strace_log && return 1
4def80
+	grep -q "/tmp/numbers/1/2/3" $strace_log && return 1
4def80
+	grep -q "/tmp/numbers/1/2/3/4" $strace_log && return 1
4def80
+	grep -q "/tmp/numbers/1/2/3/4/5" $strace_log && return 1
4def80
+	grep -q "/tmp/numbers/1/2/3/4/5/6" $strace_log && return 1
4def80
+	grep -q "/tmp/letters/a" $strace_log && return 1
4def80
+	grep -q "/tmp/letters/a/b" $strace_log && return 1
4def80
+	grep -q "/tmp/letters/a/b/c" $strace_log && return 1
4def80
+	grep -q "/tmp/letters/a/b/c/d" $strace_log && return 1
4def80
+	grep -q "/tmp/letters/a/b/c/d/e" $strace_log && return 1
4def80
+	grep -q "/tmp/letters/a/b/c/d/e/f" $strace_log && return 1
4def80
+	return 0
4def80
+}
4def80
+
4def80
+rm -rf /tmp/numbers
4def80
+mkdir -p /tmp/numbers/1/2/3/4/5/6
4def80
+rm -rf /tmp/letters
4def80
+mkdir -p /tmp/letters/a/b/c/d/e/f
4def80
+strace_log=$(mktemp)
4def80
+strace -f -e openat -o $strace_log $OSCAP oval eval --results results.xml "$srcdir/test_probes_file_multiple_file_paths.xml"
4def80
+ret=0
4def80
+check_strace_output $strace_log || ret=$?
4def80
+rm -f $strace_log
4def80
+rm -f results.xml
4def80
+rm -rf /tmp/numbers
4def80
+rm -rf /tmp/letters
4def80
+exit $ret
4def80
diff --git a/tests/probes/file/test_probes_file_multiple_file_paths.xml b/tests/probes/file/test_probes_file_multiple_file_paths.xml
4def80
new file mode 100644
4def80
index 000000000..893a3fe97
4def80
--- /dev/null
4def80
+++ b/tests/probes/file/test_probes_file_multiple_file_paths.xml
4def80
@@ -0,0 +1,42 @@
4def80
+
4def80
+<oval_definitions xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:ind="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ind-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" xmlns:unix-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" xmlns:lin-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux" xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5" xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix unix-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#independent independent-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd">
4def80
+  <generator>
4def80
+    <oval:schema_version>5.10</oval:schema_version>
4def80
+    <oval:timestamp>0001-01-01T00:00:00+00:00</oval:timestamp>
4def80
+  </generator>
4def80
+
4def80
+  <definitions>
4def80
+    <definition class="compliance" version="1" id="oval:x:def:1">
4def80
+      <metadata>
4def80
+        <title>Specify a file path using variable with two values</title>
4def80
+        <description>x</description>
4def80
+        <affected family="unix">
4def80
+          <platform>multi_platform_all</platform>
4def80
+        </affected>
4def80
+      </metadata>
4def80
+          <criteria operator="AND">
4def80
+            <criterion comment="Check multiple paths" test_ref="oval:x:tst:1"/>
4def80
+          </criteria>
4def80
+    </definition>
4def80
+  </definitions>
4def80
+
4def80
+  <tests>
4def80
+        <file_test xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" id="oval:x:tst:1" version="1" comment="Verify all paths exist" check_existence="all_exist" check="all">
4def80
+          <object object_ref="oval:x:obj:1"/>
4def80
+        </file_test>
4def80
+  </tests>
4def80
+
4def80
+  <objects>
4def80
+        <file_object xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" id="oval:x:obj:1" version="1" comment="uses var_check=all together with operation=equals">
4def80
+          <path datatype="string" var_ref="oval:x:var:1" var_check="all" operation="equals"/>
4def80
+          <filename xsi:nil="true" datatype="string"/>
4def80
+        </file_object>
4def80
+  </objects>
4def80
+
4def80
+  <variables>
4def80
+        <constant_variable datatype="string" comment="2 file paths" version="1" id="oval:x:var:1">
4def80
+            <value>/tmp/numbers</value>
4def80
+            <value>/tmp/letters</value>
4def80
+        </constant_variable>
4def80
+  </variables>
4def80
+</oval_definitions>
4def80
4def80
From 569e0013ca83adef233ddecc78a052db9b3ccc5c Mon Sep 17 00:00:00 2001
4def80
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
4def80
Date: Tue, 2 Jun 2020 15:11:37 +0200
4def80
Subject: [PATCH 2/3] Add strace to the list of test dependencies
4def80
4def80
---
4def80
 docs/developer/developer.adoc | 2 +-
4def80
 1 file changed, 1 insertion(+), 1 deletion(-)
4def80
4def80
diff --git a/docs/developer/developer.adoc b/docs/developer/developer.adoc
4def80
index 823a1504e..0f01ace74 100644
4def80
--- a/docs/developer/developer.adoc
4def80
+++ b/docs/developer/developer.adoc
4def80
@@ -152,7 +152,7 @@ After building the library you might want to run library self-checks. To do
4def80
 that you need to have these additional packages installed:
4def80
 
4def80
 ----
4def80
-wget lua which procps-ng initscripts chkconfig sendmail bzip2 rpm-build
4def80
+wget lua which procps-ng initscripts chkconfig sendmail bzip2 rpm-build strace
4def80
 ----
4def80
 
4def80
 On Ubuntu 18.04, also install:
4def80
4def80
From a47604bf30c6574e570abde4fd01488ba120f82d Mon Sep 17 00:00:00 2001
4def80
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
4def80
Date: Wed, 17 Jun 2020 11:00:02 +0200
4def80
Subject: [PATCH 3/3] Terminate matching to prevent recursion
4def80
4def80
Fixes: RHBZ#1686370
4def80
---
4def80
 src/OVAL/probes/oval_fts.c | 9 +++++++++
4def80
 1 file changed, 9 insertions(+)
4def80
4def80
diff --git a/src/OVAL/probes/oval_fts.c b/src/OVAL/probes/oval_fts.c
4def80
index 696997942..2b7314c38 100644
4def80
--- a/src/OVAL/probes/oval_fts.c
4def80
+++ b/src/OVAL/probes/oval_fts.c
4def80
@@ -1029,6 +1029,15 @@ static FTSENT *oval_fts_read_match_path(OVAL_FTS *ofts)
4def80
 
4def80
 		if (ores == OVAL_RESULT_TRUE)
4def80
 			break;
4def80
+		if (ofts->ofts_path_op == OVAL_OPERATION_EQUALS) {
4def80
+			/* At this point the comparison result isn't OVAL_RESULT_TRUE. Since
4def80
+			we passed the exact path (from filepath or path elements) to
4def80
+			fts_open() we surely know that we can't find other items that would
4def80
+			be equal. Therefore we can terminate the matching. This can happen
4def80
+			if the filepath or path element references a variable that has
4def80
+			multiple different values. */
4def80
+			return NULL;
4def80
+		}
4def80
 	} /* for (;;) */
4def80
 
4def80
 	/*