CVE-2020-27840: pytests: move Dn.validate test to ldb
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 11 Feb 2021 03:28:43 +0000 (16:28 +1300)
committerKarolin Seeger <kseeger@samba.org>
Mon, 22 Mar 2021 10:53:16 +0000 (11:53 +0100)
We had the test in the Samba Python segfault suite because
a) the signal catching infrastructure was there, and
b) the ldb tests lack Samba's knownfail mechanism, which allowed us to
   assert the failure.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14595

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/tests/python/crash.py [new file with mode: 0644]
lib/ldb/wscript
python/samba/tests/segfault.py

diff --git a/lib/ldb/tests/python/crash.py b/lib/ldb/tests/python/crash.py
new file mode 100644 (file)
index 0000000..3283981
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+#
+# Tests for crashing functions
+
+import os
+from unittest import TestCase
+import os
+import sys
+import traceback
+
+import ldb
+
+
+def segfault_detector(f):
+    def wrapper(*args, **kwargs):
+        pid = os.fork()
+        if pid == 0:
+            # child, crashing?
+            try:
+                f(*args, **kwargs)
+            except Exception as e:
+                traceback.print_exc()
+            sys.stderr.flush()
+            sys.stdout.flush()
+            os._exit(0)
+
+        # parent, waiting
+        pid2, status = os.waitpid(pid, 0)
+        if os.WIFSIGNALED(status):
+            signal = os.WTERMSIG(status)
+            raise AssertionError("Failed with signal %d" % signal)
+
+    return wrapper
+
+
+class LdbDnCrashTests(TestCase):
+    @segfault_detector
+    def test_ldb_dn_explode_crash(self):
+        for i in range(106, 150):
+            dn = ldb.Dn(ldb.Ldb(), "a=b%s,c= " % (' ' * i))
+            dn.validate()
+
+if __name__ == '__main__':
+    import unittest
+    unittest.TestProgram()
index edc3343e8273233118d8777ba1a798741a442e73..33265da373a11f92999b37d04048cce47ea2c873 100644 (file)
@@ -614,6 +614,7 @@ def test(ctx):
         os.mkdir(tmp_dir)
     pyret = samba_utils.RUN_PYTHON_TESTS(
         ['tests/python/api.py',
+         'tests/python/crash.py',
          'tests/python/index.py',
          'tests/python/repack.py'],
         extra_env={'SELFTEST_PREFIX': test_prefix})
index 70bd5b180e3fd6c40399814ddc6e1fd750763c73..07e2d46d56ad618e014bbf3b62f4985e3765aa37 100644 (file)
@@ -174,9 +174,3 @@ class SegfaultTests(samba.tests.TestCase):
     def test_dcerpc_idl_inline_arrays(self):
         """Inline arrays were incorrectly handled."""
         dnsserver.DNS_RPC_SERVER_INFO_DOTNET().pExtensions
-
-    @segfault_detector
-    def test_ldb_dn_explode_crash(self):
-        for i in range(106, 550, 5):
-            dn = ldb.Dn(ldb.Ldb(), "a=b%s,c= " % (' ' * i))
-            dn.validate()