]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
kconfig: fix potential NULL pointer dereference in conf_askvalue
authorXingjing Deng <micro6947@gmail.com>
Fri, 6 Mar 2026 02:17:09 +0000 (02:17 +0000)
committerNathan Chancellor <nathan@kernel.org>
Thu, 30 Apr 2026 01:05:44 +0000 (18:05 -0700)
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.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Xingjing Deng <micro6947@gmail.com>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Link: https://patch.msgid.link/20260306021709.27068-1-micro6947@gmail.com
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
scripts/kconfig/conf.c

index a7b44cd8ae1408892c59e4be907d853a97ce0f6a..c368bec5ab6016e26b1bd68c6619bfdc030445f1 100644 (file)
@@ -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 */