baseutils icon indicating copy to clipboard operation
baseutils copied to clipboard

libopenbsd/pwd.c, ls/ls.c: fix segfault

Open ryanwoodsmall opened this issue 4 years ago • 4 comments

libopenbsd/pwd.c, ls/ls.c: fix segfault on name lookup when uid/gid not present in /etc/passwd or /etc/group

Noticed a segfault on a name lookup for uid/gid not found; numeric IDs work as expected. This patch does a minor fixup, converting ls.c to use user_from_uid and group_from_gid with a NULL check on getpwuid and getgrgid in libopenbsd/pwd.c. Let me know if this works. Thanks!

  • https://github.com/openbsd/src/blob/master/bin/ls/ls.c
$ /usr/local/crosware/software/baseutils/baseutils-c43e028b59f3d464fcd47a872e1102ee8601df6b/bin/ls -lA /
Segmentation fault (core dumped)
$ /usr/local/crosware/software/baseutils/baseutils-c43e028b59f3d464fcd47a872e1102ee8601df6b/bin/ls -lAn /
total 8
-rwxr-xr-x    1 0     0        0 Apr 13 23:27 .dockerenv
lrwxrwxrwx    1 0     0        9 Apr  6 04:54 bin -> /usr/bin/
drwxr-xr-x   15 0     0     3780 Apr 13 23:27 dev
drwxr-xr-x    1 0     0       66 Apr 13 23:27 etc
drwxrwxr-x    4 1000  1000    59 Feb 28  2019 go-misc
drwxr-xr-x    2 0     0        6 Apr  6 04:54 home
lrwxrwxrwx    1 0     0        8 Apr  6 06:17 lib -> /usr/lib
lrwxrwxrwx    1 0     0       10 Apr  6 06:17 lib64 -> /usr/lib64
dr-xr-xr-x  193 0     0        0 Apr 13 23:27 proc
drwx------    1 0     0       22 Apr 13 23:32 root
drwxr-xr-x    2 0     0        6 Apr  6 04:54 run
lrwxrwxrwx    1 0     0        9 Apr  6 04:54 sbin -> /usr/bin/
dr-xr-xr-x   13 0     0        0 Apr  3 04:32 sys
drwxrwxrwt    3 0     0     4096 Apr 14 00:15 tmp
drwxr-xr-x    1 0     0       19 Apr  6 06:17 usr
drwxr-xr-x    1 0     0       17 Apr  6 04:54 var
$ /usr/local/crosware/software/baseutils/baseutils-c94996162fd53f817fee09e424150a88bdf8677a/bin/ls -lA /
total 8
-rwxr-xr-x    1 root  root     0 Apr 13 23:27 .dockerenv
lrwxrwxrwx    1 root  root     9 Apr  6 04:54 bin -> /usr/bin/
drwxr-xr-x   15 root  root  3780 Apr 13 23:27 dev
drwxr-xr-x    1 root  root    66 Apr 13 23:27 etc
drwxrwxr-x    4 root  root    59 Feb 28  2019 go-misc
drwxr-xr-x    2 root  root     6 Apr  6 04:54 home
lrwxrwxrwx    1 root  root     8 Apr  6 06:17 lib -> /usr/lib
lrwxrwxrwx    1 root  root    10 Apr  6 06:17 lib64 -> /usr/lib64
dr-xr-xr-x  193 root  root     0 Apr 13 23:27 proc
drwx------    1 root  root    22 Apr 13 23:32 root
drwxr-xr-x    2 root  root     6 Apr  6 04:54 run
lrwxrwxrwx    1 root  root     9 Apr  6 04:54 sbin -> /usr/bin/
dr-xr-xr-x   13 root  root     0 Apr  3 04:32 sys
drwxrwxrwt    3 root  root  4096 Apr 14 00:15 tmp
drwxr-xr-x    1 root  root    19 Apr  6 06:17 usr
drwxr-xr-x    1 root  root    17 Apr  6 04:54 var

ryanwoodsmall avatar Apr 14 '20 00:04 ryanwoodsmall

This is almost certainly fine. It's worth noting that the whole repo could use an update, but I haven't found the time to do so yet.

What OS are you running this on?

ibara avatar Apr 14 '20 01:04 ibara

Tested on Linux - Alpine, CentOS 7, and a custom GCC+musl-based build environment in Docker with bonsai linux bsd-headers (https://github.com/bonsai-linux/bsd-headers).

ryanwoodsmall avatar Apr 14 '20 01:04 ryanwoodsmall

Eek. Bonsai is undergoing a rewrite and things may be broken. My headers could potentially be the culprit.

On a side note, I love this project and hope to PR some things when I get time. 👍

mitchweaver avatar Apr 14 '20 02:04 mitchweaver

@mitchweaver - bonsai bsd-headers are working better than libbsd for me ;)

ryanwoodsmall avatar Apr 14 '20 03:04 ryanwoodsmall