git: b2af9ad17124 - stable/13 - Correctness cleanups in fsck_ffs(8).

From: Kirk McKusick <mckusick_at_FreeBSD.org>
Date: Sun, 04 Dec 2022 06:10:57 UTC
The branch stable/13 has been updated by mckusick:

URL: https://cgit.FreeBSD.org/src/commit/?id=b2af9ad171243a897a341ec3aefc5f2ea099e336

commit b2af9ad171243a897a341ec3aefc5f2ea099e336
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2022-08-13 20:27:37 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2022-12-04 05:46:51 +0000

    Correctness cleanups in fsck_ffs(8).
    
    (cherry picked from commit 6e821c35d68d4041640b27419837464ffab65cff)
    
    Sponsored by: The FreeBSD Foundation
---
 sbin/fsck_ffs/inode.c | 3 +++
 sbin/fsck_ffs/setup.c | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c
index dafc99bd92da..ccfe8782ac88 100644
--- a/sbin/fsck_ffs/inode.c
+++ b/sbin/fsck_ffs/inode.c
@@ -474,6 +474,9 @@ void
 irelse(struct inode *ip)
 {
 
+	/* Check for failed inode read */
+	if (ip->i_bp == NULL)
+		return;
 	if (ip->i_bp->b_refcnt <= 0)
 		pfatal("irelse: releasing unreferenced ino %ju\n",
 		    (uintmax_t) ip->i_number);
diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c
index 14b34962d3fe..05c044395436 100644
--- a/sbin/fsck_ffs/setup.c
+++ b/sbin/fsck_ffs/setup.c
@@ -174,6 +174,7 @@ setup(char *dev)
 	/*
 	 * allocate and initialize the necessary maps
 	 */
+	bufinit();
 	bmapsize = roundup(howmany(maxfsblock, CHAR_BIT), sizeof(short));
 	blockmap = Calloc((unsigned)bmapsize, sizeof (char));
 	if (blockmap == NULL) {
@@ -198,7 +199,6 @@ setup(char *dev)
 		    (uintmax_t)numdirs * sizeof(struct inoinfo *));
 		goto badsb;
 	}
-	bufinit();
 	if (sblock.fs_flags & FS_DOSOFTDEP)
 		usedsoftdep = 1;
 	else