mirror of
https://github.com/systemd/systemd.git
synced 2024-11-23 18:23:32 +08:00
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).
This commit is contained in:
parent
0f90d4f0c3
commit
2b5e786005
@ -2708,6 +2708,7 @@ inst_binary() {
|
||||
# DSOs provided by systemd
|
||||
local systemd_so_regex='/(libudev|libsystemd.*|.+[\-_]systemd([\-_].+)?|libnss_(mymachines|myhostname|resolve)).so'
|
||||
local wrap_binary=0
|
||||
local enable_lsan=0
|
||||
# I love bash!
|
||||
while read -r line; do
|
||||
[[ "$line" = 'not a dynamic executable' ]] && break
|
||||
@ -2750,6 +2751,14 @@ inst_binary() {
|
||||
bin_rx='/(agetty|chown|curl|delv|dig|getfacl|getent|id|login|ls|mkfs\.[a-z0-9]+|mksquashfs|mkswap|setfacl|setpriv|stat|su|tar|useradd|userdel)$'
|
||||
if get_bool "$IS_BUILT_WITH_ASAN" && [[ "$bin" =~ $bin_rx ]]; then
|
||||
wrap_binary=1
|
||||
# Ugh, so we want to disable LSan in most cases for the wrapped binaries, since
|
||||
# we don't care about memory leaks in such binaries. However, in certain cases
|
||||
# the external binary is the only interface for the systemd code, like for
|
||||
# the systemd NSS modules, where we want to detect memory leaks. So let's
|
||||
# do another check to decide if we want to enable LSan for given binary.
|
||||
if [[ "$bin" =~ /getent$ ]]; then
|
||||
enable_lsan=1
|
||||
fi
|
||||
fi
|
||||
|
||||
# If the target binary is built with ASan support, we don't need to wrap
|
||||
@ -2767,7 +2776,7 @@ inst_binary() {
|
||||
export LD_PRELOAD="$ASAN_RT_PATH"
|
||||
# Disable LSan to speed things up, since we don't care about leak reports
|
||||
# from 'external' binaries
|
||||
export ASAN_OPTIONS=detect_leaks=0
|
||||
export ASAN_OPTIONS=detect_leaks=$enable_lsan
|
||||
# Set argv[0] to the original binary name without the ".orig" suffix
|
||||
exec -a "\$0" -- "${target}.orig" "\$@"
|
||||
EOF
|
||||
|
Loading…
Reference in New Issue
Block a user