git: 6e821c35d68d - main - Correctness cleanups in fsck_ffs(8).

From: Kirk McKusick <mckusick_at_FreeBSD.org>
Date: Sat, 13 Aug 2022 20:28:57 UTC
The branch main has been updated by mckusick:

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

commit 6e821c35d68d4041640b27419837464ffab65cff
Author:     Kirk McKusick <mckusick@FreeBSD.org>
AuthorDate: 2022-08-13 20:27:37 +0000
Commit:     Kirk McKusick <mckusick@FreeBSD.org>
CommitDate: 2022-08-13 20:28:31 +0000

    Correctness cleanups in fsck_ffs(8).
    
    Allocation or I/O failures in fsck_ffs(8) could cause segment
    faults because of missing checks or not-yet-initialized data
    structures. Correct these issues.
    
    Reported by:  Peter Holm
    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 47f72c84a1f2..8a93ad092a4a 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 022799117eb0..3db59e611729 100644
--- a/sbin/fsck_ffs/setup.c
+++ b/sbin/fsck_ffs/setup.c
@@ -145,6 +145,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) {
@@ -169,7 +170,6 @@ setup(char *dev)
 		    (uintmax_t)numdirs * sizeof(struct inoinfo *));
 		goto badsb;
 	}
-	bufinit();
 	if (sblock.fs_flags & FS_DOSOFTDEP)
 		usedsoftdep = 1;
 	else