The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=690ae8a2025ca1ce58d08a90a1df1645c81392ea
commit 690ae8a2025ca1ce58d08a90a1df1645c81392ea Author: Kirk McKusick <mckus...@freebsd.org> AuthorDate: 2025-08-22 05:33:48 +0000 Commit: Kirk McKusick <mckus...@freebsd.org> CommitDate: 2025-08-22 05:33:48 +0000 Bail out of corrupt directory entries during boot A directory with a zero-valued d_reclen causes boot to hang, This patch checks for directory entries with value zero and bails out rather than spin forever. The hope is that the user has other options. Sadly this was reported on Jun 16 2015 and is just now attended to as part of a sweep of old unclosed phabricator reports. Reported-by: Daniel O'Connor darius-dons.net.au Differential Revision: https://reviews.freebsd.org/D2844 MFC-after: 1 week Sponsored-by: Netflix --- stand/libsa/ufs.c | 6 ++++++ stand/libsa/ufsread.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/stand/libsa/ufs.c b/stand/libsa/ufs.c index 86cd3be9a27a..868e8d47dbbd 100644 --- a/stand/libsa/ufs.c +++ b/stand/libsa/ufs.c @@ -891,6 +891,12 @@ ufs_readdir(struct open_file *f, struct dirent *d) if (error) return (error); dp = (struct direct *)buf; + /* + * Check for corrupt directory entry and bail out rather + * than spin forever hoping that the user has other options. + */ + if (dp->d_reclen == 0) + return (0); fp->f_seekp += dp->d_reclen; } while (dp->d_ino == (ino_t)0); diff --git a/stand/libsa/ufsread.c b/stand/libsa/ufsread.c index 0f9b9bb4e2fb..86ac8fbbbab7 100644 --- a/stand/libsa/ufsread.c +++ b/stand/libsa/ufsread.c @@ -108,6 +108,13 @@ fsfind(const char *name, ufs_ino_t * ino) *ino = d.d_ino; return d.d_type; } + /* + * Check for corrupt directory entry and bail out + * rather than spin forever hoping that the user + * has other options. + */ + if (d.d_reclen == 0) + return 0; s += d.d_reclen; } if (n != -1 && ls)