Skip to contentSkip to conversation

bcachefs: avoid using strlen() to determine whether label is empty

PATCH New [email protected] 1 participant 1 message Nov 9, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcachefs: avoid using strlen() to determine whether label is empty

The "label" field in "struct bch_sb" is not guaranteed to be null-terminated. Therefore, juding the first character is safer than using strlen().

This patch fixes issue koverstreet/bcachefs-tools#341.

---
 fs/bcachefs/super-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/bcachefs/super-io.c +1 -1
index c83bd3dedb1b..c612319ba901 100644
@@ -1322,7 +1322,7 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb,
 	prt_printf(out, "Device index:\t%u\n", sb->dev_idx);
 
 	prt_printf(out, "Label:\t");
-	if (!strlen(sb->label))
+	if (!sb->label[0])
 		prt_printf(out, "(none)");
 	else
 		prt_printf(out, "%.*s", (int) sizeof(sb->label), sb->label);
Signature · 1 line
2.47.0