bcachefs: avoid using strlen() to determine whether label is empty
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.
Signed-off-by [email protected] <[email protected]>
--- fs/bcachefs/super-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/bcachefs/super-io.c +1 -1
@@ -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