Re: [PATCH] kconfig: fix potential NULL pointer dereference in conf_askvalue
From: Nathan Chancellor
Date: Wed Feb 25 2026 - 14:45:59 EST
On Wed, Feb 25, 2026 at 07:22:46AM +0000, Xingjing Deng wrote:
> In conf_askvalue(), the 'def' argument (retrieved via sym_get_string_value)
> can be NULL. When the symbol is not changeable, the code calls
> printf("%s\n", def), which leads to a segmentation fault on certain
> systems/libc implementations when passing a NULL pointer to %s.
How do you reproduce this segmentation fault? Surely someone would have
hit this if it were a real problem given the Fixes tag? Or is this a
corner case?
> This patch adds a check to ensure 'def' is not NULL before printing.
> Additionally, it removes the redundant re-initialization of the 'line'
> buffer inside the !sym_is_changeable(sym) block, as it is already
> initialized at the beginning of the function.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Xingjing Deng <micro6947@xxxxxxxxx>
> ---
> scripts/kconfig/conf.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
> index a7b44cd8a..2771bc84e 100644
> --- a/scripts/kconfig/conf.c
> +++ b/scripts/kconfig/conf.c
> @@ -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 ? 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 ? def : "");
> return 0;
> }
> /* fall through */
> --
> 2.25.1
>