kconfig: fix potential NULL pointer dereference in conf_askvalue
PATCH v3 1/1 kconfig: fix potential NULL pointer dereference in conf_askvalue
In conf_askvalue(), the 'def' argument (retrieved via sym_get_string_value) can be NULL. While current call sites ensure that 'def' is valid, calling printf("%s\n", def) is technically undefined behavior and could lead to a segmentation fault on certain libc implementations if the function were called with a NULL pointer in the future.
Improve the robustness of conf_askvalue() by providing an empty string as a fallback.
Additionally, remove the redundant re-initialization of the 'line' buffer inside the !sym_is_changeable(sym) block, as it is already properly initialized at the function entry.
---
v3:
- fix compile errors.
- Link to v2: https://lore.kernel.org/all/[email protected]/
v2:
- Change commit message and use fewer characters in modify.
- Link to v1: https://lore.kernel.org/all/[email protected]/
scripts/kconfig/conf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
scripts/kconfig/conf.c +2 -4
@@ -297,9 +297,7 @@ static int conf_askvalue(struct symbol *sym, const char *def) line[1 ] =0 ;if (!sym_is_changeable (sym)) { -printf ("%s\n" , def); - line[0 ] ='\n' ; - line[1 ] =0 ; +printf ("%s\n" , def ?:"" );return 0 ; }
@@ -307,7 +305,7 @@ static int conf_askvalue(struct symbol *sym, const char *def)case oldconfig:case syncconfig:if (sym_has_value (sym)) { -printf ("%s\n" , def); +printf ("%s\n" , def ?:"" );return 0 ; }/* fall through */
Signature · 1 line
2.25.1
Nathan Chancellor
maintainerQuoted 1 line · Xingjing Deng
kconfig: fix potential NULL pointer dereference in
conf_askvalue
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/kbuild/linux.git kbuild-next-unstable
Thanks!
[1/1] kconfig: fix potential NULL pointer dereference in conf_askvalue
https://git.kernel.org/kbuild/c/b9d21c32dca21
Please look out for regression or issue reports or other follow up comments, as they may result in the patch/series getting dropped or reverted. Patches applied to an "unstable" branch are accepted pending wider testing in -next and any post-commit review; they will generally be moved to the main branch in a week if no issues are found.
Best regards,
Signature · 2 lines
Cheers, Nathan