diff options
author | Elliott Hughes <enh@google.com> | 2017-05-23 17:35:49 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2017-05-24 19:56:58 -0500 |
commit | 12f0744f340746b3a1c1accfdf993d6548f33e56 (patch) | |
tree | 7fa4ac6625bcaff12c300f4ef54d53649cfe7628 /toys/other | |
parent | 5a159cceb35fe08e444bd5a1771f8059888b03ff (diff) | |
download | toybox-12f0744f340746b3a1c1accfdf993d6548f33e56.tar.gz |
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).
Diffstat (limited to 'toys/other')
-rw-r--r-- | toys/other/hexedit.c | 2 | ||||
-rw-r--r-- | toys/other/modinfo.c | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/toys/other/hexedit.c b/toys/other/hexedit.c index ffa304c3..3c5ada3a 100644 --- a/toys/other/hexedit.c +++ b/toys/other/hexedit.c @@ -140,7 +140,7 @@ void hexedit_main(void) for (pos = TT.len, TT.numlen = 0; pos; pos >>= 4, TT.numlen++); TT.numlen += (4-TT.numlen)&3; - TT.data = mmap(0, TT.len, PROT_READ|(PROT_WRITE*!ro), MAP_SHARED, fd, 0); + TT.data = xmmap(0, TT.len, PROT_READ|(PROT_WRITE*!ro), MAP_SHARED, fd, 0); draw_page(); for (;;) { 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) |