aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Branco <rbranco@suse.de>2024-01-03 20:32:47 +0000
committerXin LI <delphij@FreeBSD.org>2024-01-04 09:00:23 +0000
commit1fb3caee72241b9b4dacbfb0109c972a86d4401f (patch)
tree19350fde9365f08de9a88e062cfabf524e44d4d5
parente23954bd42fe4331b67ba8f6446bcccf751096f1 (diff)
tail: Do not trust st_size if it equals zero.
PR: bin/276107 MFC after: 1 week
-rw-r--r--usr.bin/tail/forward.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/usr.bin/tail/forward.c b/usr.bin/tail/forward.c
index 010a36b4c793..a5303385a74f 100644
--- a/usr.bin/tail/forward.c
+++ b/usr.bin/tail/forward.c
@@ -102,7 +102,7 @@ forward(FILE *fp, const char *fn, enum STYLE style, off_t off, struct stat *sbp)
case FBYTES:
if (off == 0)
break;
- if (S_ISREG(sbp->st_mode)) {
+ if (S_ISREG(sbp->st_mode) && sbp->st_size > 0) {
if (sbp->st_size < off)
off = sbp->st_size;
if (fseeko(fp, off, SEEK_SET) == -1) {
@@ -134,7 +134,7 @@ forward(FILE *fp, const char *fn, enum STYLE style, off_t off, struct stat *sbp)
}
break;
case RBYTES:
- if (S_ISREG(sbp->st_mode)) {
+ if (S_ISREG(sbp->st_mode) && sbp->st_size > 0) {
if (sbp->st_size >= off &&
fseeko(fp, -off, SEEK_END) == -1) {
ierr(fn);
@@ -151,7 +151,7 @@ forward(FILE *fp, const char *fn, enum STYLE style, off_t off, struct stat *sbp)
return;
break;
case RLINES:
- if (S_ISREG(sbp->st_mode))
+ if (S_ISREG(sbp->st_mode) && sbp->st_size > 0)
if (!off) {
if (fseeko(fp, (off_t)0, SEEK_END) == -1) {
ierr(fn);