From: Guillem Jover Date: Sat, 15 Jun 2019 12:33:32 +0000 (+0200) Subject: nlist: Check whether the nl argument is not NULL X-Git-Tag: 0.10.0~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3aaedb12086a77c5ea7564eb3b5b2f02f788fe61;p=thirdparty%2Flibbsd.git nlist: Check whether the nl argument is not NULL This prevents programming errors. Reported-by: Daniel Hodson Based-on-patch-by: Daniel Hodson Signed-off-by: Guillem Jover --- diff --git a/man/nlist.3bsd b/man/nlist.3bsd index 7dd2377..beb32a3 100644 --- a/man/nlist.3bsd +++ b/man/nlist.3bsd @@ -72,7 +72,10 @@ The last entry in the list is always The number of invalid entries is returned if successful; otherwise, if the file .Fa filename -does not exist or is not executable, the returned value is \-1. +does not exist or is not executable, +or the nl pointer is +.Dv NULL , +the returned value is \-1. .Sh SEE ALSO .Xr elf 5 .Sh HISTORY diff --git a/src/nlist.c b/src/nlist.c index 0932f59..776d315 100644 --- a/src/nlist.c +++ b/src/nlist.c @@ -258,6 +258,10 @@ nlist(const char *name, struct nlist *list) { int fd, n; + if (list == NULL) { + errno = EINVAL; + return (-1); + } fd = open(name, O_RDONLY, 0); if (fd < 0) return (-1);