bcachefs: Ensure bad d_type doesn't oops in bch2_dirent_to_text()

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2021-07-12 23:17:15 -04:00 committed by Kent Overstreet
parent 0a70089062
commit 003e738d4f
2 changed files with 5 additions and 2 deletions

View 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,

View 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",