Skip to content

Commit a30f322

Browse files
donutAneesKent Overstreet
authored andcommitted
bcachefs: Fix NULL pointer dereference in bch2_opt_to_text
This patch adds a bounds check to the bch2_opt_to_text function to prevent NULL pointer dereferences when accessing the opt->choices array. This ensures that the index used is within valid bounds before dereferencing. The new version enhances the readability. Reported-and-tested-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=37186860aa7812b331d5 Signed-off-by: Mohammed Anees <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent a154154 commit a30f322

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/bcachefs/opts.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,9 @@ void bch2_opt_to_text(struct printbuf *out,
427427
prt_printf(out, "%lli", v);
428428
break;
429429
case BCH_OPT_STR:
430-
if (flags & OPT_SHOW_FULL_LIST)
430+
if (v < opt->min || v >= opt->max - 1)
431+
prt_printf(out, "(invalid option %lli)", v);
432+
else if (flags & OPT_SHOW_FULL_LIST)
431433
prt_string_option(out, opt->choices, v);
432434
else
433435
prt_str(out, opt->choices[v]);

0 commit comments

Comments
 (0)