Blame SOURCES/openscap-1.3.6-PR-1788-test-rhbz1959570.patch

3c0c1e
From 05faede8f6602b7b71d71fd965276225a986fb1f Mon Sep 17 00:00:00 2001
3c0c1e
From: =?UTF-8?q?Jan=20=C4=8Cern=C3=BD?= <jcerny@redhat.com>
3c0c1e
Date: Wed, 28 Jul 2021 13:06:25 +0200
3c0c1e
Subject: [PATCH] Add a regression test for rhbz#1959570
3c0c1e
3c0c1e
The bug was a segmentation fault in filehash58 probe which happened
3c0c1e
in openscap-1.3.3-6.el8_3.
3c0c1e
3c0c1e
The bug was fixed by https://github.com/OpenSCAP/openscap/pull/1779
3c0c1e
and this patch adds a very small test.
3c0c1e
---
3c0c1e
 tests/probes/filehash58/CMakeLists.txt        |  1 +
3c0c1e
 .../probes/filehash58/rhbz1959570_segfault.sh | 19 +++++++++
3c0c1e
 .../rhbz1959570_segfault_reproducer.xml       | 39 +++++++++++++++++++
3c0c1e
 3 files changed, 59 insertions(+)
3c0c1e
 create mode 100755 tests/probes/filehash58/rhbz1959570_segfault.sh
3c0c1e
 create mode 100644 tests/probes/filehash58/rhbz1959570_segfault_reproducer.xml
3c0c1e
3c0c1e
diff --git a/tests/probes/filehash58/CMakeLists.txt b/tests/probes/filehash58/CMakeLists.txt
3c0c1e
index b26d8171fb..cdec0792eb 100644
3c0c1e
--- a/tests/probes/filehash58/CMakeLists.txt
3c0c1e
+++ b/tests/probes/filehash58/CMakeLists.txt
3c0c1e
@@ -1,3 +1,4 @@
3c0c1e
 if(ENABLE_PROBES_INDEPENDENT)
3c0c1e
 	add_oscap_test("test_probes_filehash58.sh")
3c0c1e
+	add_oscap_test("rhbz1959570_segfault.sh")
3c0c1e
 endif()
3c0c1e
diff --git a/tests/probes/filehash58/rhbz1959570_segfault.sh b/tests/probes/filehash58/rhbz1959570_segfault.sh
3c0c1e
new file mode 100755
3c0c1e
index 0000000000..0c32cc79f1
3c0c1e
--- /dev/null
3c0c1e
+++ b/tests/probes/filehash58/rhbz1959570_segfault.sh
3c0c1e
@@ -0,0 +1,19 @@
3c0c1e
+#!/usr/bin/env bash
3c0c1e
+
3c0c1e
+# Copyright 2021 Red Hat Inc., Durham, North Carolina.
3c0c1e
+# All Rights Reserved.
3c0c1e
+#
3c0c1e
+# OpenSCAP Probes Test Suite.
3c0c1e
+#
3c0c1e
+# Authors:
3c0c1e
+#      Jan Černý, <jcerny@redhat.com>
3c0c1e
+
3c0c1e
+set -e -o pipefail
3c0c1e
+. $builddir/tests/test_common.sh
3c0c1e
+
3c0c1e
+# Test Cases
3c0c1e
+
3c0c1e
+stderr="$(mktemp)"
3c0c1e
+$OSCAP oval eval --id oval:x:def:1 "$srcdir/rhbz1959570_segfault_reproducer.xml" 2> "$stderr"
3c0c1e
+[ ! -s "$stderr" ]
3c0c1e
+rm "$stderr"
3c0c1e
diff --git a/tests/probes/filehash58/rhbz1959570_segfault_reproducer.xml b/tests/probes/filehash58/rhbz1959570_segfault_reproducer.xml
3c0c1e
new file mode 100644
3c0c1e
index 0000000000..4b3fc4863a
3c0c1e
--- /dev/null
3c0c1e
+++ b/tests/probes/filehash58/rhbz1959570_segfault_reproducer.xml
3c0c1e
@@ -0,0 +1,39 @@
3c0c1e
+
3c0c1e
+<oval-def:oval_definitions xmlns:ind="http://oval.mitre.org/XMLSchema/oval-definitions-5#independent" xmlns:linux="http://oval.mitre.org/XMLSchema/oval-definitions-5#linux" xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:unix="http://oval.mitre.org/XMLSchema/oval-definitions-5#unix" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd         http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-definitions-schema.xsd         http://oval.mitre.org/XMLSchema/oval-definitions-5#independent independent-definitions-schema.xsd         http://oval.mitre.org/XMLSchema/oval-definitions-5#unix unix-definitions-schema.xsd         http://oval.mitre.org/XMLSchema/oval-definitions-5#linux linux-definitions-schema.xsd">
3c0c1e
+  <oval-def:generator>
3c0c1e
+    <oval:product_name>jcerny</oval:product_name>
3c0c1e
+    <oval:product_version>1</oval:product_version>
3c0c1e
+    <oval:schema_version>5.11</oval:schema_version>
3c0c1e
+    <oval:timestamp>2021-07-28T07:40:55</oval:timestamp>
3c0c1e
+  </oval-def:generator>
3c0c1e
+  <oval-def:definitions>
3c0c1e
+    <oval-def:definition class="compliance" id="oval:x:def:1" version="1">
3c0c1e
+      <oval-def:metadata>
3c0c1e
+        <oval-def:title>title</oval-def:title>
3c0c1e
+        <oval-def:description>description</oval-def:description>
3c0c1e
+      </oval-def:metadata>
3c0c1e
+      <oval-def:criteria>
3c0c1e
+        <oval-def:criterion comment="comment" test_ref="oval:x:tst:1"/>
3c0c1e
+      </oval-def:criteria>
3c0c1e
+    </oval-def:definition>
3c0c1e
+  </oval-def:definitions>
3c0c1e
+  <oval-def:tests>
3c0c1e
+    <ind:filehash58_test check="all" check_existence="all_exist" comment="comment" id="oval:x:tst:1" version="1">
3c0c1e
+      <ind:object object_ref="oval:x:obj:1"/>
3c0c1e
+      <ind:state state_ref="oval:x:ste:1"/>
3c0c1e
+    </ind:filehash58_test>
3c0c1e
+  </oval-def:tests>
3c0c1e
+  <oval-def:objects>
3c0c1e
+    <ind:filehash58_object id="oval:x:obj:1" version="1">
3c0c1e
+      <ind:filepath>/etc/os-release</ind:filepath>
3c0c1e
+      <ind:hash_type>SHA-256</ind:hash_type>
3c0c1e
+    </ind:filehash58_object>
3c0c1e
+  </oval-def:objects>
3c0c1e
+  <oval-def:states>
3c0c1e
+    <ind:filehash58_state id="oval:x:ste:1" version="1">
3c0c1e
+      <ind:filepath>/etc/os-release</ind:filepath>
3c0c1e
+      <ind:hash_type>SHA-256</ind:hash_type>
3c0c1e
+      <ind:hash>6488c757642cd493da09dd78ee27f039711a1ad79039900970553772fd2106af</ind:hash>
3c0c1e
+    </ind:filehash58_state>
3c0c1e
+  </oval-def:states>
3c0c1e
+</oval-def:oval_definitions>