Dear Maintainer, I am not even sure this is a bug in finger, maybe there is just crap in utmp/wtmp, and finger has no way of behaving differently, but as it is a segfault, I report it nevertheless. finger segfaults on me, as in: ralph@pi:~$ finger finger: /dev//pts/6: No such file or directory Login Name Tty Idle Login Time Office Office Phone ralph Ralph Aichinger pts/0 1:11 Sep 1 10:46 (IP redacted) ralph Ralph Aichinger pts/1 Sep 1 12:15 (IP redacted) ralph Ralph Aichinger pts/2 Sep 1 12:17 (IP redacted) Segmentation fault while e.g. w or who work just fine ralph@pi:~$ w 12:21:02 up 54 days, 14:51, 5 users, load average: 0.08, 0.04, 0.01 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT ralph pts/0 83.XXX.XXX.XXX 10:46 1:15m 0.06s 0.06s -bash ralph pts/1 83.XXX.XXX.XXX 12:15 22.00s 3.56s 0.39s /usr/bin/nvim /tmp/reportbug-finger-20220901121727-8h0p ralph pts/2 83.XXX.XXX.XXX 12:17 3:26 0.06s 0.06s -bash ralph pts/3 83.XXX.XXX.XXX 12:20 6.00s 0.05s 0.00s w ralph@pi:~$ ls /dev/pts/ 0 1 2 3 ptmx
Dear Maintainer,
Same trouble on my side with a Debian Sid amd64 system
and here is what coredumpctl says:
Stack trace of thread 3773275:
#0 0x000055d59ac16ad5 stimeprint (finger + 0x3ad5)
#1 0x000055d59ac15779 main (finger + 0x2779)
#2 0x00007f067262118a __libc_start_call_main (libc.so.6 + 0x2718a)
#3 0x00007f0672621245 __libc_start_main_impl (libc.so.6 + 0x27245)
#4 0x000055d59ac1599a _start (finger + 0x299a)
ELF object binary architecture: AMD x86-64
Regards,
Patrice
Looking into this, I found this note: usr.bin/finger/util.c 1.29 In find_idle_and_ttywrite(), initialize idletime and writable to 0 when stat() fails. this prevents a coredump later in stimeprint() due to gmtime() returning NULL for an uninitialized idletime. [chs, ticket #1137] here : http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/doc/Attic/CHANGES-7.1?rev=1.1.2.106.2.2&content-type=text/plain Regarding https://sources.debian.org/src/bsd-finger/0.17-17/finger/util.c/ it seems that the version here is: #ifndef lint /*static char sccsid[] = "from: @(#)util.c 5.14 (Berkeley) 1/17/91";*/ char util_rcsid[] = "$Id: util.c,v 1.18 1999/09/28 22:53:58 netbug Exp $"; #endif /* not lint */ I do not know if the Linux port of those BSD tools is still maintained somewhere and how hard it is to package them into Debian. Sure here: http://ftp.linux.org.uk/pub/linux/Networking/netkit/ everything seems frozen since 2000-07-31. There is also: http://ftp.linux.org.uk/pub/linux/Networking/netkit-devel/ where it exists a 0.18-pre1 version dating 2002-08-01. But I hope it helps!
I’ve hit the same issue:
Running `finger` can segfault when utmp contains entries whose tty paths do not exist, e.g. /dev//seat0 or /dev//pts/N.
Observed:
finger: /dev//seat0: No such file or directory
Segmentation fault
finger is segfaulting in bsd-finger’s short-format idle-time printer:
finger/sprint.c:161, inside stimeprint():
delta = gmtime(&w->idletime);
if (!delta->tm_yday)
gmtime() is returning NULL, then finger immediately dereferences delta.
The bad input is the first logged-in WHERE record:
tty = "seat0"
loginat = 1777546298
idletime = 4210143749954891109
That huge idletime is garbage. It comes from finger/util.c:find_idle_and_ttywrite(): it tries to stat /dev//seat0, fails,
prints:
finger: /dev//seat0: No such file or directory
and returns without initializing w->idletime or w->writable. Then sflag_print() treats the record as logged in and calls
stimeprint(w), where the bogus idletime makes gmtime() fail.
So the immediate segfault is sprint.c:161; the underlying bug is the failed stat() path in util.c:find_idle_and_ttywrite()
leaving w->idletime uninitialized.
The crash is in finger/sprint.c:stimeprint():
delta = gmtime(&w->idletime);
if (!delta->tm_yday)
`w->idletime` is left uninitialized in finger/util.c:find_idle_and_ttywrite() when stat(tbuf, &sb) fails. In my case it
contained a huge garbage value, causing gmtime() to return NULL and the next line to dereference it.
In find_idle_and_ttywrite(), initialize idletime and writable to 0
when stat() fails. this prevents a coredump later in stimeprint()
due to gmtime() returning NULL for an uninitialized idletime.
NetBSD appears to have fixed the same issue by initializing idletime and writable to 0 on stat failure:
https://groups.google.com/g/linux.debian.bugs.dist/c/jEaGqvHwAmw
Minimal fix:
if (stat(tbuf, &sb) < 0) {
eprintf("finger: %s: %s\n", tbuf, strerror(errno));
w->idletime = 0;
w->writable = 0;
return;
}
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.