bcachefs: Ensure bad d_type doesn't oops in bch2_dirent_to_text()
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 13 Jul 2021 03:17:15 +0000 (23:17 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:08 +0000 (17:09 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/dirent.c
fs/bcachefs/opts.c

index d5883ab7de21d899df1a28ea591d4ecbd8df78e9..a95165b8eddf97fa352a1ae577b6337b21d6402e 100644 (file)
@@ -112,7 +112,10 @@ void bch2_dirent_to_text(struct printbuf *out, struct bch_fs *c,
 
        bch_scnmemcpy(out, d.v->d_name,
                      bch2_dirent_name_bytes(d));
-       pr_buf(out, " -> %llu type %s", d.v->d_inum, bch2_d_types[d.v->d_type]);
+       pr_buf(out, " -> %llu type %s", d.v->d_inum,
+              d.v->d_type < DT_MAX
+              ? bch2_d_types[d.v->d_type]
+              : "(bad d_type)");
 }
 
 static struct bkey_i_dirent *dirent_create_key(struct btree_trans *trans,
index fd3f7cddb9abb24cf8f1e15b9b8b369f83f8062f..5de296078219fc42e749193624d4c7fca4a3f25f 100644 (file)
@@ -63,7 +63,7 @@ const char * const bch2_member_states[] = {
 
 #undef x
 
-const char * const bch2_d_types[] = {
+const char * const bch2_d_types[DT_MAX] = {
        [DT_UNKNOWN]    = "unknown",
        [DT_FIFO]       = "fifo",
        [DT_CHR]        = "chr",