Skip to content

Commit 5a29fbb

Browse files
mrc0mmandbluca
authored andcommitted
test: enable LSan for certain wrapped binaries
So we're able to detect memory leaks in our NSS modules. An example after introducing a memory leak in nss-myhostname.c: testsuite-71.sh[2881]: ================================================================= testsuite-71.sh[2881]: ==2880==ERROR: LeakSanitizer: detected memory leaks testsuite-71.sh[2881]: Direct leak of 2 byte(s) in 1 object(s) allocated from: testsuite-71.sh[2881]: #0 0x7fa28907243b in strdup (/usr/lib64/libasan.so.8.0.0+0x7243b) testsuite-71.sh[2881]: #1 0x7fa286a7bc10 in gethostname_full ../src/basic/hostname-util.c:67 testsuite-71.sh[2881]: #2 0x7fa286a74af9 in gethostname_malloc ../src/basic/hostname-util.h:24 testsuite-71.sh[2881]: #3 0x7fa286a756f4 in _nss_myhostname_gethostbyname4_r ../src/nss-myhostname/nss-myhostname.c:79 testsuite-71.sh[2881]: #4 0x7fa288f17588 in getaddrinfo (/lib64/libc.so.6+0xf4588) testsuite-71.sh[2881]: #5 0x7fa2890a4d93 in __interceptor_getaddrinfo.part.0 (/usr/lib64/libasan.so.8.0.0+0xa4d93) testsuite-71.sh[2881]: #6 0x55a54b2b7159 in ahosts_keys_int.part.0 (/usr/bin/getent.orig+0x4159) testsuite-71.sh[2881]: SUMMARY: AddressSanitizer: 2 byte(s) leaked in 1 allocation(s). (cherry picked from commit 2b5e786)
1 parent a90ec12 commit 5a29fbb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

test/test-functions

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2687,6 +2687,7 @@ inst_binary() {
26872687
# DSOs provided by systemd
26882688
local systemd_so_regex='/(libudev|libsystemd.*|.+[\-_]systemd([\-_].+)?|libnss_(mymachines|myhostname|resolve)).so'
26892689
local wrap_binary=0
2690+
local enable_lsan=0
26902691
# I love bash!
26912692
while read -r line; do
26922693
[[ "$line" = 'not a dynamic executable' ]] && break
@@ -2728,6 +2729,14 @@ inst_binary() {
27282729
bin_rx='/(agetty|chown|curl|delv|dig|getfacl|getent|login|ls|mkfs\.[a-z0-9]+|mksquashfs|mkswap|setpriv|stat|su|tar|useradd|userdel)$'
27292730
if get_bool "$IS_BUILT_WITH_ASAN" && [[ "$bin" =~ $bin_rx ]]; then
27302731
wrap_binary=1
2732+
# Ugh, so we want to disable LSan in most cases for the wrapped binaries, since
2733+
# we don't care about memory leaks in such binaries. However, in certain cases
2734+
# the external binary is the only interface for the systemd code, like for
2735+
# the systemd NSS modules, where we want to detect memory leaks. So let's
2736+
# do another check to decide if we want to enable LSan for given binary.
2737+
if [[ "$bin" =~ /getent$ ]]; then
2738+
enable_lsan=1
2739+
fi
27312740
fi
27322741

27332742
# If the target binary is built with ASan support, we don't need to wrap
@@ -2745,7 +2754,7 @@ inst_binary() {
27452754
export LD_PRELOAD="$ASAN_RT_PATH"
27462755
# Disable LSan to speed things up, since we don't care about leak reports
27472756
# from 'external' binaries
2748-
export ASAN_OPTIONS=detect_leaks=0
2757+
export ASAN_OPTIONS=detect_leaks=$enable_lsan
27492758
# Set argv[0] to the original binary name without the ".orig" suffix
27502759
exec -a "\$0" -- "${target}.orig" "\$@"
27512760
EOF

0 commit comments

Comments
 (0)