Skip to content

strtonum: don't abort on EINVAL from strtoi

Duncan Overbruck requested to merge Duncaen/libbsd:musl-fixes into main

The closefrom testcase failed with musl libc because of the . directory.

Program received signal SIGABRT, Aborted.
__restore_sigs (set=set@entry=0x7fffffffea10) at ./arch/x86_64/syscall_arch.h:40
warning: 40     ./arch/x86_64/syscall_arch.h: No such file or directory
(gdb) bt
#0  __restore_sigs (set=set@entry=0x7fffffffea10) at ./arch/x86_64/syscall_arch.h:40
#1  0x00007ffff7fa6700 in raise (sig=sig@entry=6) at src/signal/raise.c:11
#2  0x00007ffff7f6a6d0 in abort () at src/exit/abort.c:13
#3  0x00007ffff7f347a5 in strtonum (nptr=0x5555555580ab ".", minval=minval@entry=4, maxval=maxval@entry=2147483647, errstr=errstr@entry=0x7fffffffeb50) at ./src/strtonum.c:69
#4  0x00007ffff7f3609d in closefrom_procfs (lowfd=4) at ./src/closefrom.c:156
#5  closefrom (lowfd=lowfd@entry=4) at ./src/closefrom.c:213
#6  0x000055555555514f in main (argc=<optimized out>, argv=<optimized out>) at ./test/closefrom.c:61

Two separate commits one that avoids the abort() if EINVAL is returned and one that ignores directories starting with dot when scanning the file descriptor directory, since there is not really a point in going through strtonum for that.

Merge request reports