From 4f2554b7b7ee236ead2b2be8a84a22402993ff60 Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Mon, 26 Mar 2001 19:29:49 +0000 Subject: [PATCH] rlines() checks: 1) really check for size overflow by checking negative value. 2) since mmap() not support files over INT_MAX size, add check for it until either mmap() will be fixed or tail will be rewritted to handle large files alternatively. 3) replace fseek(... file_size, SEEK_SET) with fseek(... 0L, SEEK_END) to avoid off_t -> long cast 4) Use exit() if file is too big instead of warning and wrong logic afterwards. --- usr.bin/tail/forward.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/usr.bin/tail/forward.c b/usr.bin/tail/forward.c index e25e0d60a74..f63b410dcb2 100644 --- a/usr.bin/tail/forward.c +++ b/usr.bin/tail/forward.c @@ -274,10 +274,17 @@ rlines(fp, off, sbp) if (!(size = sbp->st_size)) return; - if (size > SIZE_T_MAX) { + if (size > SIZE_T_MAX || size < 0) { errno = EFBIG; ierr(); - return; + exit(1); + } + + /* XXX: FIXME - mmap() not support files over 2Gb */ + if (size > INT_MAX) { + errno = EFBIG; + ierr(); + exit(1); } if ((start = mmap(NULL, (size_t)size, @@ -296,7 +303,7 @@ rlines(fp, off, sbp) /* Set the file pointer to reflect the length displayed. */ size = sbp->st_size - size; WR(p, size); - if (fseek(fp, (long)sbp->st_size, SEEK_SET) == -1) { + if (fseek(fp, 0L, SEEK_END) == -1) { ierr(); return; }