[PATCH v4] kconfig: check for a NULL pointer before access
From: Bill Wendling
Date: Thu Jun 26 2025 - 20:42:56 EST
The call to 'prop_get_symbol' may return NULL in some cases. The if-then
statement accesses the returned value without cheecking if it's
non-NULL. After inlining, the compiler may treat the conditional as
'undefined behavior', which the compiler may take the opportunity to do
whatever it wants with the UB path. This patch simply adds a check to
ensure that 'def_sym' is non-NULL to avoid this behavior.
Signed-off-by: Bill Wendling <morbo@xxxxxxxxxx>
---
Cc: Masahiro Yamada <masahiroy@xxxxxxxxxx>
Cc: Randy Dunlap <rdunlap@xxxxxxxxxxxxx>
Cc: linux-kbuild@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
v4:
- Fix issue with patch formatting.
- Patch is sent from original email account.
v3:
- Fix whitespace for real now.
- Patch from another email account so that the whitespace is retained.
v2:
- Fix whitespace
---
scripts/kconfig/symbol.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index d57f8cbba291..9c5068225328 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -272,7 +272,7 @@ struct symbol *sym_choice_default(struct menu *choice)
if (prop->visible.tri == no)
continue;
def_sym = prop_get_symbol(prop);
- if (def_sym->visible != no)
+ if (def_sym && def_sym->visible != no)
return def_sym;
}
--
2.50.0.727.gbf7dc18ff4-goog