]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
selftest: Fix address sanitizer with python3
authorAndreas Schneider <asn@samba.org>
Tue, 6 Sep 2022 06:59:56 +0000 (08:59 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 8 Sep 2022 22:34:36 +0000 (22:34 +0000)
==9542==AddressSanitizer: failed to intercept 'crypt'
==9542==AddressSanitizer: failed to intercept 'crypt_r'

[..]

AddressSanitizer:DEADLYSIGNAL
=================================================================
==29768==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000000000 bp 0x7ffcec4bf3c0 sp 0x7ffcec4beb58 T0)
==29768==Hint: pc points to the zero page.
==29768==The signal is caused by a READ memory access.
==29768==Hint: address points to the zero page.
    #0 0x0  (<unknown module>)
    #1 0x7f052cca4129 in crypt_crypt_impl /usr/src/debug/python310-core-3.10.6-3.1.x86_64/Modules/_cryptmodule.c:44

We would need to build python without --as-needed as we can't so that
we need to preload the library to avoid a segfault.

See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98669

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
selftest/selftest.pl
selftest/wscript

index 3332de632ad05a32d28682fda9a27194f7c9f700..11f8e92e84eb9232e54ff7da3d283690d37fccef 100755 (executable)
@@ -62,6 +62,7 @@ my $opt_libresolv_wrapper_so_path = "";
 my $opt_libsocket_wrapper_so_path = "";
 my $opt_libuid_wrapper_so_path = "";
 my $opt_libasan_so_path = "";
+my $opt_libcrypt_so_path = "";
 my $opt_use_dns_faking = 0;
 my @testlists = ();
 
@@ -248,6 +249,7 @@ my $result = GetOptions (
                'socket_wrapper_so_path=s' => \$opt_libsocket_wrapper_so_path,
                'uid_wrapper_so_path=s' => \$opt_libuid_wrapper_so_path,
                'asan_so_path=s' => \$opt_libasan_so_path,
+               'crypt_so_path=s' => \$opt_libcrypt_so_path,
                'use-dns-faking' => \$opt_use_dns_faking
            );
 
@@ -346,9 +348,17 @@ my $ld_preload = $ENV{LD_PRELOAD};
 
 if ($opt_libasan_so_path) {
        if ($ld_preload) {
-               $ld_preload = "$opt_libasan_so_path:$ld_preload";
+               if ($opt_libcrypt_so_path) {
+                       $ld_preload = "$opt_libasan_so_path:$opt_libcrypt_so_path:$ld_preload";
+               } else {
+                       $ld_preload = "$opt_libasan_so_path:$ld_preload";
+               }
        } else {
-               $ld_preload = "$opt_libasan_so_path";
+               if ($opt_libcrypt_so_path) {
+                       $ld_preload = "$opt_libasan_so_path:$opt_libcrypt_so_path";
+               } else {
+                       $ld_preload = "$opt_libasan_so_path";
+               }
        }
 }
 
index a8b6d45cd1d882e7f3e605fcdf848e57da397eeb..03637c521650cecbde5889ceb238451b830fc829 100644 (file)
@@ -291,6 +291,14 @@ def cmd_testonly(opt):
         # Have the selftest.pl LD_PRELOAD libasan in the right spot
         env.OPTIONS += " --asan_so_path=" + libasan
 
+        if CONFIG_SET(opt, 'HAVE_CRYPT_R'):
+            # We try to find the correct libcrypt automatically
+            libcrypt = Utils.cmd_output(
+                'ldd bin/modules/ldb/password_hash.so | awk \'/libcrypt.so/ { print $3 }\'',
+                silent=True).strip()
+            libcrypt = libcrypt.decode('utf8')
+            env.OPTIONS += " --crypt_so_path=" + libcrypt
+
     subunit_cache = None
     # We use the full path rather than relative path to avoid problems on some platforms (ie. solaris 8).
     env.CORE_COMMAND = '${PERL} ${srcdir}/selftest/selftest.pl --target=${SELFTEST_TARGET} --prefix=${SELFTEST_PREFIX} --srcdir=${srcdir} --exclude=${srcdir}/selftest/skip ${TESTLISTS} ${OPTIONS} ${TESTS}'