All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Schier <nsc@kernel.org>
To: Erkan Erdem <hexvalid@gmail.com>
Cc: Nathan Chancellor <nathan@kernel.org>,
	Julian Braha <julianbraha@gmail.com>,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	llvm@lists.linux.dev
Subject: Re: [PATCH v2] kconfig: preserve the final answer when input has no newline
Date: Fri, 4 Dec 2026 17:29:24 +0100	[thread overview]
Message-ID: <axLqZHHfY-xYv2y_@levanger> (raw)
In-Reply-To: <20260907103739.23212-2-hexvalid@gmail.com>

On Mon, Sep 07, 2026 at 01:37:38PM +0300, Erkan Erdem wrote:
> conf_string() unconditionally removes the last character returned by
> fgets(), assuming that it is a newline. When redirected input ends
> without a newline, the last character is part of the answer instead.
> For example, feeding 42 to an integer prompt stores 4, and feeding
> 0xff to a hexadecimal prompt stores 0xf. Both commands succeed despite
> silently changing the supplied value.
> 
> Strip the newline with strcspn() so that a complete answer at EOF is
> preserved. Keep the existing handling of newline-terminated and empty
> answers unchanged.
> 
> Add regression tests for string, int and hex answers, with and without
> a final newline, in oldaskconfig and oldconfig.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Assisted-by: LLM
> Signed-off-by: Erkan Erdem <hexvalid@gmail.com>
> ---
> 
> Changes in v2, addressing Julian Braha's review:
> - Add an in-tree regression test under scripts/kconfig/tests for string,
>   int and hex answers, with and without a final newline, in oldconfig
>   and oldaskconfig. The shared test harness is unchanged.
> - Submit this fix independently of the checkkconfigsymbols.py change.
> - Refresh Cc from scripts/get_maintainer.pl, including the LLVM contacts.
> 
> v1: https://lore.kernel.org/all/20260905123237.40670-1-hexvalid@gmail.com/
> 
> An AI coding assistant found the issue, prepared the fix and changelog,
> and ran the original verification. The assistant also prepared the new
> regression test and this v2 revision.
> 
> Validation:
> - Built original and fixed conf with Clang on macOS and GCC in an
>   x86_64 Linux container, using -Wall -Wmissing-prototypes
>   -Wstrict-prototypes -Werror.
> - On both platforms, the original conf fails all six unterminated-input
>   cases and passes all six newline-terminated controls.
> - The fixed conf passes the complete 33-test Kconfig suite on both
>   platforms, including all 12 new cases.
> - This tests the host configuration tool; a complete kernel was not built.
> 
>  scripts/kconfig/conf.c                        |  2 +-
>  .../kconfig/tests/conf_no_newline/__init__.py | 32 +++++++++++++++++++
>  2 files changed, 33 insertions(+), 1 deletion(-)
>  create mode 100644 scripts/kconfig/tests/conf_no_newline/__init__.py
> 
> diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
> index fe8ba09b0..46c9ca646 100644
> --- a/scripts/kconfig/conf.c
> +++ b/scripts/kconfig/conf.c
> @@ -343,7 +343,7 @@ static int conf_string(struct menu *menu)
>  			}
>  			/* fall through */
>  		default:
> -			line[strlen(line)-1] = 0;
> +			line[strcspn(line, "\n")] = 0;

What about this instead of the "complex" strcspn():

size_t len = strlen(line);
if (line[len-1] == '\n')
	line[len-1] = 0;

>  			def = line;
>  		}
>  		if (def && sym_set_string_value(sym, def))
> diff --git a/scripts/kconfig/tests/conf_no_newline/__init__.py b/scripts/kconfig/tests/conf_no_newline/__init__.py
> new file mode 100644
> index 000000000..0fca696d2
> --- /dev/null
> +++ b/scripts/kconfig/tests/conf_no_newline/__init__.py

Did you see Julians feedback?  Or did I miss v3?

Kind regards,
Nicolas


      parent reply	other threads:[~2026-12-04 16:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07 10:37 [PATCH v2] kconfig: preserve the final answer when input has no newline Erkan Erdem
2026-09-09 22:43 ` Julian Braha
2026-12-04 16:29 ` Nicolas Schier [this message]

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=axLqZHHfY-xYv2y_@levanger \
    --to=nsc@kernel.org \
    --cc=hexvalid@gmail.com \
    --cc=julianbraha@gmail.com \
    --cc=justinstitt@google.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    /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.