Skip to content

Commit

Permalink
tail: Do not trust st_size if it equals zero.
Browse files Browse the repository at this point in the history
PR:		bin/276107
MFC after:	1 week
  • Loading branch information
ricardobranco777 authored and delphij committed Jan 4, 2024
1 parent e23954b commit 1fb3cae
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions usr.bin/tail/forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 1fb3cae

Please sign in to comment.