wsh: fix a crash when a symbol can't be loaded #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In case a symbol can be loaded dlsym() returns NULL. This need to be handled instead of blindly passing the 0 address do dladdr(), otherwise that causes a crash:
$ ./bin/wsh
init
WARNING: No binary loaded in memory. Try loadbin(). For help type help("loadbin").
[SIGSEGV] Read 0x19 (address not mapped to object)
0x7f7edd231cb1 /lib/x86_64-linux-gnu/libc.so.6(+0x14fcb1)
0x42017f52 ./bin/wsh(scan_syms+0x152)
0x420183c8 ./bin/wsh(parse_link_map_dyn+0x58)
0x4201c371 ./bin/wsh(wsh_run+0x61)
0x4200ecba ./bin/wsh(main+0x3a)
0x7f7edd10520a /lib/x86_64-linux-gnu/libc.so.6(+0x2320a)
0x7f7edd1052bc /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x7c)
0x4200ed0a ./bin/wsh(_start+0x2a)
Segmentation fault (core dumped)
This is reproducible for instance when wsh has been built against glibc <= 2.33, but executed on glibc >= 2.34. This is due to the merge of libdl.so into libc.so, resulting in libdl.so only containing weak symbols. wsh then crashes when trying to dlsym the _ITM_deregisterTMCloneTable symbol.
Rebuilding wcc against glibc >= 2.34 workarounds the problem as the resulting wsh binary is not linked against libdl.so anymore.