Skip to contentSkip to conversation

xfs_db: fix inverted logic in error path

PATCH In review Darrick J. Wong 2 participants 3 messages Apr 11, 2023 – Apr 12, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_db: fix inverted logic in error path

From: Darrick J. Wong <[email protected]>

smatch complains proceeding into the if body if leaf is a null pointer. This is backwards, so correct that.

check.c:3455 process_leaf_node_dir_v2_int() warn: variable dereferenced before check 'leaf'

---
 db/check.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
db/check.c +1 -1
index 964756d0..d5f3d225 100644
@@ -3452,7 +3452,7 @@ process_leaf_node_dir_v2_int(
 				 id->ino, dabno, stale,
 				 be16_to_cpu(leaf3->hdr.stale));
 		error++;
-	} else if (!leaf && stale != be16_to_cpu(leaf->hdr.stale)) {
+	} else if (leaf && stale != be16_to_cpu(leaf->hdr.stale)) {
 		if (!sflag || v)
 			dbprintf(_("dir %lld block %d stale mismatch "
 				 "%d/%d\n"),
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

smatch complains proceeding into the if body if leaf is a null pointer. This is backwards, so correct that.

check.c:3455 process_leaf_node_dir_v2_int() warn: variable dereferenced before check 'leaf'

---
 db/check.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
db/check.c +0 -0
index 964756d0..d5f3d225 100644

db/check.c process_leaf_node_dir_v2_int( · line 3458

Quoted 8 lines
db/check.c +1 -1
@@ -3452,7 +3452,7 @@ process_leaf_node_dir_v2_int(
 				 id->ino, dabno, stale,
 				 be16_to_cpu(leaf3->hdr.stale));
 		error++;
-	} else if (!leaf && stale != be16_to_cpu(leaf->hdr.stale)) {
+	} else if (leaf && stale != be16_to_cpu(leaf->hdr.stale)) {
 		if (!sflag || v)
 			dbprintf(_("dir %lld block %d stale mismatch "
 				 "%d/%d\n"),

Looks good. I'm surprised the compiler didn't warn about this obviously broken code...

Signature · 2 lines
Dave Chinner
[email protected]
author NAK
#2 lore raw
Quoted 30 lines · Dave Chinner
Quoted 17 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

smatch complains proceeding into the if body if leaf is a null pointer. This is backwards, so correct that.

check.c:3455 process_leaf_node_dir_v2_int() warn: variable dereferenced before check 'leaf'

---
 db/check.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
db/check.c +0 -0
index 964756d0..d5f3d225 100644

db/check.c process_leaf_node_dir_v2_int( · line 3458

Quoted 8 lines
db/check.c +1 -1
@@ -3452,7 +3452,7 @@ process_leaf_node_dir_v2_int(
 				 id->ino, dabno, stale,
 				 be16_to_cpu(leaf3->hdr.stale));
 		error++;
-	} else if (!leaf && stale != be16_to_cpu(leaf->hdr.stale)) {
+	} else if (leaf && stale != be16_to_cpu(leaf->hdr.stale)) {
 		if (!sflag || v)
 			dbprintf(_("dir %lld block %d stale mismatch "
 				 "%d/%d\n"),

Looks good. I'm surprised the compiler didn't warn about this obviously broken code...

Quoted 1 line

NAK, this logic is actually trying to switch between the V4 and V5 directory format logic, but it's using the subtlety that @leaf3 is a
null pointer for a V4 fs and non-null for a V5 fs. Hence this check
really should be:

	} else if (!leaf3 && stale != be16_to_cpu(leaf->hdr.stale)) {

Even though that looks *totally* wrong. But xfs_check is deprecated, so fmeh.

So I'll go fix that and rerun through testing. I had thought this was fine, but xfs/291 barfed up errors overnight.

--D

Quoted 3 lines
Signature · 2 lines
Dave Chinner
[email protected]