diff mbox series

[1/5] xfs_db: improve error message when unknown btree type given to btheight

Message ID 173689081897.3476119.13308060628733838470.stgit@frogsfrogsfrogs (mailing list archive)
State New
Headers show
Series [1/5] xfs_db: improve error message when unknown btree type given to btheight | expand

Commit Message

Darrick J. Wong Jan. 14, 2025, 9:40 p.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

I found accidentally that if you do this (note 'rmap', not 'rmapbt'):

xfs_db /dev/sda -c 'btheight -n 100 rmap'

The program spits back "Numerical result out of range".  That's the
result of it failing to match "rmap" against a known btree type, and
falling back to parsing the string as if it were a btree geometry
description.

Improve this a little by checking that there's at least one semicolon in
the string so that the error message improves to:

"rmap: expected a btree geometry specification"

Fixes: cb1e69c564c1e0 ("xfs_db: add a function to compute btree geometry")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 db/btheight.c |    6 ++++++
 1 file changed, 6 insertions(+)

Comments

Christoph Hellwig Jan. 15, 2025, 5:19 a.m. UTC | #1
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/db/btheight.c b/db/btheight.c
index 6643489c82c4c9..98165b522e4f6f 100644
--- a/db/btheight.c
+++ b/db/btheight.c
@@ -145,6 +145,12 @@  construct_records_per_block(
 		}
 	}
 
+	p = strchr(tag, ':');
+	if (!p) {
+		fprintf(stderr, _("%s: expected a btree geometry specification.\n"), tag);
+		return -1;
+	}
+
 	toktag = strdup(tag);
 	ret = -1;