Fix crash when running ELF w/ interpreter missing#10199
Fix crash when running ELF w/ interpreter missing#10199faho merged 1 commit intofish-shell:Integration_3.7.0from ksyx:interpreter-patch
Conversation
The function `stat` as defined in `include/x86_64-linux-gnu/sys/stat.h` marks its arguments as nonnull as in below. This UB causes crash in release builds with variable `interpreter` assumed to be nonnull. Along with failing stat returning nonzero value, this ultimately causes `strlen` to be called with NULL as argument. Definition of `stat`: ``` extern int stat (const char *__restrict __file, struct stat *__restrict __buf) __THROW __nonnull ((1, 2)); ``` Reproduce: ``` > # interp.c is any vaild single file C source > gcc ./interp.c -Wl,--dynamic-linker=/bad -o interp > echo './interp' > in.txt > ./fish < in.txt './fish < in.txt' terminated by signal SIGSEGV (Address boundary error) ``` Co-authored-by: Moody Liu <mooodyhunter@outlook.com>
|
I can't reproduce this crash with 3.6.0, 3.7.0 or master on Linux. What environment are you using? (I get the expected (I probably wouldn't roll a 3.7.1 for this fix alone.) |
|
Hi @zanchey, it is an Arch Linux build with GCC 13 The build script is at Passing NULL to |
|
I can reproduce this and I don't see any reason not to merge it. We already have #10187 on Integration_3.7.0, so if we do end up making another C++-release this'll be included. Thanks! (to be clear: What crashes is the "postfork" fish, so the outer fish sees a segfault. it's not a huge deal, just a misleading error) |
Description
The function
statas defined ininclude/x86_64-linux-gnu/sys/stat.hmarks its arguments as nonnull as in below. This UB causes crash in release builds with variableinterpreterassumed to be nonnull. Along with failingstatreturning nonzero value, this ultimately causesstrlento be called with NULL as argument. This PR fixes the problem by prefixingstatcall with a check to avoid calling it with NULL argument.Definition of
stat:Reproduce:
Problem identified and fixed together with @moodyhunter
TODOs: