Re: [PATCH v2 2/5] kconfig: check for out-of-bounds numeric constants
From: Nicolas Schier
Date: Thu Sep 17 2026 - 11:27:04 EST
On Tue, Sep 15, 2026 at 10:15:05PM +0100, Julian Braha wrote:
> The Kconfig interpreter internally represents constants as strings, then
> attempts to parse them as 64-bit signed integers for 'int' options, and
> 64-bit unsigned integers for 'hex' options.
>
> However, there is currently no check that the conversion succeeds, leading
> to failures when the values are actually used. For example:
>
> config LARGE_INT
> int
> default 10000000000000000000
>
> config BUGGED_INT_COMPARISON
> bool
> default y if LARGE_INT < 2
>
> Obviously 10000000000000000000 is larger than 2, but the Kconfig
> interpreter will fallback to comparing the two values with strcmp() after
> the numeric conversion fails, causing the first character, '1', to be
> compared with '2', and giving the wrong result.
>
> Since none of these out-of-bounds values are used as constants anywhere in
> the tree, we can already make these error out.
>
> Assisted-by: LLM
> Signed-off-by: Julian Braha <julianbraha@xxxxxxxxx>
> ---
> scripts/kconfig/menu.c | 60 ++++++++++----
> scripts/kconfig/tests/err_num_bounds/Kconfig | 79 +++++++++++++++++++
> .../kconfig/tests/err_num_bounds/__init__.py | 12 +++
> .../tests/err_num_bounds/expected_stderr | 10 +++
> .../err_num_non_numeric_ref/expected_stderr | 30 +++----
> 5 files changed, 160 insertions(+), 31 deletions(-)
> create mode 100644 scripts/kconfig/tests/err_num_bounds/Kconfig
> create mode 100644 scripts/kconfig/tests/err_num_bounds/__init__.py
> create mode 100644 scripts/kconfig/tests/err_num_bounds/expected_stderr
>
Reviewed-by: Nicolas Schier <n.schier@xxxxxxxxx>
--
Nicolas