From 12f0744f340746b3a1c1accfdf993d6548f33e56 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 23 May 2017 17:35:49 -0700 Subject: Add and use xmmap. Everyone forgets that mmap returns MAP_FAILED rather than NULL on failure. Every use of mmap in toybox was either doing the wrong check, or no check at all (including the two I personally added). --- toys/other/modinfo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'toys/other/modinfo.c') diff --git a/toys/other/modinfo.c b/toys/other/modinfo.c index 69cdf27e..1178d675 100644 --- a/toys/other/modinfo.c +++ b/toys/other/modinfo.c @@ -46,7 +46,8 @@ static void modinfo_file(char *full_name) if (-1 != (fd = open(full_name, O_RDONLY))) { len = fdlength(fd); - if (!(buf = mmap(0, len, PROT_READ, MAP_SHARED, fd, 0))) close(fd); + buf = xmmap(0, len, PROT_READ, MAP_SHARED, fd, 0); + close(fd); } if (!buf) { @@ -69,7 +70,6 @@ static void modinfo_file(char *full_name) } munmap(buf, len); - close(fd); } static int check_module(struct dirtree *new) -- cgit v1.2.3