From 40fbe3a922b9969eb6176b33cd687813dbae8811 Mon Sep 17 00:00:00 2001 From: mckusick Date: Sat, 2 Mar 2019 21:30:01 +0000 Subject: [PATCH] Properly calculate the last used logical block of a file when checking inodes that reference directories. While here tighten the check for comparing the last logical block with the end of the file. Reported by: Peter Holm Tested by: Peter Holm Sponsored by: Netflix --- sbin/fsck_ffs/inode.c | 4 ++-- sbin/fsck_ffs/pass1.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c index 79c1c29436b..19b1cb26b54 100644 --- a/sbin/fsck_ffs/inode.c +++ b/sbin/fsck_ffs/inode.c @@ -127,9 +127,9 @@ ckinode(union dinode *dp, struct inodesc *idesc) ret = iblock(idesc, i + 1, remsize, BT_LEVEL1 + i); if (ret & STOP) return (ret); - } else { + } else if (remsize > 0) { idesc->id_lbn += sizepb / sblock.fs_bsize; - if (idesc->id_type == DATA && remsize > 0) { + if (idesc->id_type == DATA) { /* An empty block in a directory XXX */ getpathname(pathbuf, idesc->id_number, idesc->id_number); diff --git a/sbin/fsck_ffs/pass1.c b/sbin/fsck_ffs/pass1.c index 2245ee3fa84..15c34e0c935 100644 --- a/sbin/fsck_ffs/pass1.c +++ b/sbin/fsck_ffs/pass1.c @@ -439,7 +439,7 @@ checkinode(ino_t inumber, struct inodesc *idesc, int rebuildcg) * at its end. */ if (DIP(dp, di_size) > UFS_NDADDR * sblock.fs_bsize && - idesc->id_lballoc != lblkno(&sblock, DIP(dp, di_size) - 1)) { + idesc->id_lballoc < lblkno(&sblock, DIP(dp, di_size) - 1)) { fixsize = lblktosize(&sblock, idesc->id_lballoc + 1); pwarn("INODE %lu: FILE SIZE %ju BEYOND END OF ALLOCATED FILE, " "SIZE SHOULD BE %ju", (u_long)inumber, -- 2.45.0