scripts: kconfig: fix deref after null in menu.c
PATCH 1/1 scripts: kconfig: fix deref after null in menu.c
From: Anton Moryakov <[email protected]>
Static analyzer detected a potential NULL pointer dereference when 'sym' pointer is passed to for_all_prompts() and other functions after being checked for NULL earlier in the function.
The issue could occur when called from gstr get_relations_str() with NULL symbol pointer.
Changes made:
1. Added early return if sym is NULL or has no name
2. Added NULL checks before all sym pointer dereferences
3. Maintained existing functionality for valid symbols
--- scripts/kconfig/menu.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
scripts/kconfig/menu.c +9 -3
@@ -796,6 +796,9 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym, {struct property *prop; +if (!sym || !sym->name) +return ; +if (sym && sym->name) {str_printf (r,"Symbol: %s [=%s]\n" , sym->name,sym_get_string_value (sym));
@@ -809,7 +812,8 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym, } } } - for_all_prompts(sym, prop) +if (sym) + for_all_prompts(sym, prop)get_prompt_str (r, prop, head); prop =get_symbol_prop (sym);
@@ -823,14 +827,16 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym, } } -get_symbol_props_str (r, sym,P_SELECT ," Selects: " ); +if (sym) +get_symbol_props_str (r, sym,P_SELECT ," Selects: " );if (sym->rev_dep.expr) {expr_gstr_print_revdep (sym->rev_dep.expr, r, yes," Selected by [y]:\n" );expr_gstr_print_revdep (sym->rev_dep.expr, r, mod," Selected by [m]:\n" );expr_gstr_print_revdep (sym->rev_dep.expr, r, no," Selected by [n]:\n" ); } -get_symbol_props_str (r, sym,P_IMPLY ," Implies: " ); +if (sym) +get_symbol_props_str (r, sym,P_IMPLY ," Implies: " );if (sym->implied.expr) {expr_gstr_print_revdep (sym->implied.expr, r, yes," Implied by [y]:\n" );expr_gstr_print_revdep (sym->implied.expr, r, mod," Implied by [m]:\n" );
Signature · 1 line
2.30.2
Quoted 14 lines · On Fri, May 16, 2025 at 05:56:11PM +0300, [email protected] wrote:
From: Anton Moryakov <[email protected]>
Static analyzer detected a potential NULL pointer dereference when 'sym' pointer is passed to
for_all_prompts()and other functions after being checked for NULL earlier in the function.The issue could occur when called from gstr
get_relations_str()with NULL symbol pointer.Changes made:
1. Added early return if sym is NULL or has no name
2. Added NULL checks before all sym pointer dereferences
3. Maintained existing functionality for valid symbols
Quoted 4 lines
Signed-off-by Anton Moryakov <[email protected]>--- scripts/kconfig/menu.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
Since this comes from the linux kernel, please see if it's a problem there still (and report it please) or backport the fix, thanks.
Signature · 1 line
Tom