MFC: hexdump: Do not trust st_size if it equals zero.

PR:		bin/276106

(cherry picked from commit e23954bd42)
This commit is contained in:
Ricardo Branco 2024-01-03 21:17:58 +01:00 • committed by Xin LI
parent 0bb4c188d3
commit 538bf98c7c

View file

@ -397,13 +397,14 @@ doskip(const char *fname, int statok)
if (statok) {
if (fstat(fileno(stdin), &sb))
err(1, "%s", fname);
if (S_ISREG(sb.st_mode) && skip > sb.st_size) {
if (S_ISREG(sb.st_mode) && skip > sb.st_size && sb.st_size > 0) {
address += sb.st_size;
skip -= sb.st_size;
return;
}
}
if (!statok || S_ISFIFO(sb.st_mode) || S_ISSOCK(sb.st_mode)) {
if (!statok || S_ISFIFO(sb.st_mode) || S_ISSOCK(sb.st_mode) || \
(S_ISREG(sb.st_mode) && sb.st_size == 0)) {
noseek();
return;
}