From 530d2d67b529359de3ab3e75f53fcf16a43ea8b7 Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Tue, 5 May 2020 18:06:32 +0000 Subject: [PATCH] ls(1): Fix trivial SEGV due to NULL deref in OOM path Reported by: Anton Rang Sponsored by: Dell EMC Isilon --- bin/ls/ls.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bin/ls/ls.c b/bin/ls/ls.c index 3929dd47be5a..3410ea0619a1 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -838,7 +838,21 @@ display(const FTSENT *p, FTSENT *list, int options) group = ngroup; } else { user = user_from_uid(sp->st_uid, 0); + /* + * user_from_uid(..., 0) only returns + * NULL in OOM conditions. We could + * format the uid here, but (1) in + * general ls(1) exits on OOM, and (2) + * there is another allocation/exit + * path directly below, which will + * likely exit anyway. + */ + if (user == NULL) + err(1, "user_from_uid"); group = group_from_gid(sp->st_gid, 0); + /* Ditto. */ + if (group == NULL) + err(1, "group_from_gid"); } if ((ulen = strlen(user)) > maxuser) maxuser = ulen;