`w` SIGSEGVs if called without access to `/proc`
the tool w
can SIGSEGV if the call made to opendir("/proc")
during readproctab
fails due to lack of permission.
the crash is ultimately manifested by a failure to check if procs
is NULL prior to use here:
https://gitlab.com/procps-ng/procps/-/blob/3c1fed7d650c35b11a452e5005abcfb90f126667/w.c#L371
here is the output of crashing program:
13:06:46 up 244 days, 7 min, 108 users, load average: 65.74, 66.33, 65.97
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
Segmentation fault (core dumped)
here is the relevent line from $ strace w
demonstrating that the syscall failed:
open("/proc", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 EACCES (Permission denied)
note: this issue appears to be fixed in the branch newlib
so this issue relates to master.
$ gdb w
(gdb) r
Starting program: /usr/bin/w
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
13:12:12 up 244 days, 13 min, 106 users, load average: 65.91, 65.01, 65.36
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
Program received signal SIGSEGV, Segmentation fault.
0x0000000000402578 in ?? ()
(gdb) x/15i $pc-35
0x402555: cwtl
0x402556: add (%rax),%al
0x402558: add %bl,0x5d(%rbx)
0x40255b: pop %r12
0x40255d: pop %r13
0x40255f: pop %r14
0x402561: pop %r15
0x402563: retq
0x402564: nopl 0x0(%rax)
0x402568: mov $0xffffffff,%r13d
0x40256e: lea 0x55(%rsp),%rdi
0x402573: callq 0x401270 <tty_to_dev@plt>
=> 0x402578: mov 0x0(%rbp),%rcx
0x40257c: test %rcx,%rcx
0x40257f: je 0x40253b
if you agree that this is an issue and would like me to make a patch fixing the issue please let me know.