All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xingjing Deng <micro6947@gmail.com>
To: nathan@kernel.org, nsc@kernel.org, rdunlap@infradead.org,
	masahiroy@kernel.org
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Xingjing Deng <micro6947@gmail.com>
Subject: [PATCH] kconfig: fix potential NULL pointer dereference in conf_askvalue
Date: Wed, 25 Feb 2026 07:22:46 +0000	[thread overview]
Message-ID: <20260225072246.3475275-1-micro6947@gmail.com> (raw)

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.

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@gmail.com>
---
 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


             reply	other threads:[~2026-02-25  7:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25  7:22 Xingjing Deng [this message]
2026-02-25 19:44 ` [PATCH] kconfig: fix potential NULL pointer dereference in conf_askvalue Nathan Chancellor
2026-02-26  1:25   ` Xingjing Deng
2026-02-26 20:35     ` Nathan Chancellor
2026-03-01  5:31       ` Xingjing Deng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260225072246.3475275-1-micro6947@gmail.com \
    --to=micro6947@gmail.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=rdunlap@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.