summaryrefslogtreecommitdiff
path: root/usr.bin/look
diff options
context:
space:
mode:
authorColin Percival <cperciva@FreeBSD.org>2009-08-26 03:30:06 +0000
committerColin Percival <cperciva@FreeBSD.org>2009-08-26 03:30:06 +0000
commitf9f231846a10c0ce03c2f132bf28f0465316b71b (patch)
treef804a7f73a0d6ad57a8762cc41db8fe1e1cc175a /usr.bin/look
parent74d1c4927a3b7ce785e41e97e33a804f4f8c62ce (diff)
downloadsrc-test-f9f231846a10c0ce03c2f132bf28f0465316b71b.tar.gz
src-test-f9f231846a10c0ce03c2f132bf28f0465316b71b.zip
Don't try to mmap the contents of empty files. This behaviour was harmless
prior to r195693, since historical behaviour of mmap(2) was to silently ignore length-zero mmap requests; but mmap now returns EINVAL, which caused look(1) to emit an error message and fail. Among other things, this makes `freebsd-update fetch` on a newly installed 8.0-BETA3 system print bogus warning messages. MFC after: 3 days
Notes
Notes: svn path=/head/; revision=196558
Diffstat (limited to 'usr.bin/look')
-rw-r--r--usr.bin/look/look.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/usr.bin/look/look.c b/usr.bin/look/look.c
index e6fd1b8b9e269..7c590c7de0819 100644
--- a/usr.bin/look/look.c
+++ b/usr.bin/look/look.c
@@ -140,6 +140,10 @@ main(int argc, char *argv[])
err(2, "%s", file);
if (sb.st_size > SIZE_T_MAX)
errx(2, "%s: %s", file, strerror(EFBIG));
+ if (sb.st_size == 0) {
+ close(fd);
+ continue;
+ }
if ((front = mmap(NULL, (size_t)sb.st_size, PROT_READ, MAP_SHARED, fd, (off_t)0)) == MAP_FAILED)
err(2, "%s", file);
back = front + sb.st_size;