From 003e738d4f0f61a8711ce41a03d8fb01a1cd7733 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Mon, 12 Jul 2021 23:17:15 -0400 Subject: [PATCH] bcachefs: Ensure bad d_type doesn't oops in bch2_dirent_to_text() Signed-off-by: Kent Overstreet --- fs/bcachefs/dirent.c | 5 ++++- fs/bcachefs/opts.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/bcachefs/dirent.c b/fs/bcachefs/dirent.c index d5883ab7de21..a95165b8eddf 100644 --- a/fs/bcachefs/dirent.c +++ b/fs/bcachefs/dirent.c @@ -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, diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c index fd3f7cddb9ab..5de296078219 100644 --- a/fs/bcachefs/opts.c +++ b/fs/bcachefs/opts.c @@ -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",