diff options
author | ache <ache@FreeBSD.org> | 2001-03-26 19:29:49 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2001-03-26 19:29:49 +0000 |
commit | f087b10f53a010670ca8a55790a860d82a430ea9 (patch) | |
tree | 1c3c5855f58a537f9acb4272360509e89709f6cb | |
parent | 91cc89dd77c2fc5dc25b55adea1779ddd18e719e (diff) | |
download | FreeBSD-src-f087b10f53a010670ca8a55790a860d82a430ea9.zip FreeBSD-src-f087b10f53a010670ca8a55790a860d82a430ea9.tar.gz |
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.
-rw-r--r-- | usr.bin/tail/forward.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/usr.bin/tail/forward.c b/usr.bin/tail/forward.c index e25e0d6..f63b410 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; } |