mirror of
https://github.com/torvalds/linux.git
synced 2026-10-23 15:32:04 +02:00
kconfig: check for hex and int mismatches
Using a numeric option of one type (e.g. 'int') to determine the value of
a different numeric type (e.g. 'hex') currently fails silently in various
ways if attempted, because the underlying string representation is naively
reused.
Example 1:
config I
int
default -1
config HEX_DEFAULT_INT
hex
default I
Here, HEX_DEFAULT_INT actually gets set to '0x-1', which is of course not
a valid hex value.
Example 2:
config H
hex
default A
config INT_DEFAULT_HEX
int
default H
Here, INT_DEFAULT_HEX actually gets set to 'A', without even converting
into the base-10 equivalent of 10. This value, 'A', is otherwise a
rejected int value if entered in the frontend, or read in from an existing
.config file.
These int-hex mismatches currently do not appear anywhere in the tree, so
it is already safe to make these error out.
Assisted-by: LLM
Signed-off-by: Julian Braha <julianbraha@gmail.com>
Reviewed-by: Nicolas Schier <n.schier@fritz.com>
Link: https://patch.msgid.link/20260915211508.291790-4-julianbraha@gmail.com
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
This commit is contained in:
parent
a5e84d6f6d
commit
d13bad83d8
|
|
@ -244,7 +244,7 @@ static int menu_validate_number(struct symbol *sym, struct symbol *sym2,
|
|||
if (sym->type != S_INT && sym->type != S_HEX)
|
||||
return 0;
|
||||
|
||||
if (sym2->type == S_INT || sym2->type == S_HEX)
|
||||
if (sym2->type == sym->type)
|
||||
return 0;
|
||||
|
||||
if (sym2->type != S_UNKNOWN ||
|
||||
|
|
|
|||
38
scripts/kconfig/tests/err_num_mismatch/Kconfig
Normal file
38
scripts/kconfig/tests/err_num_mismatch/Kconfig
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
# Test 'int' and 'hex' symbols that reference each other
|
||||
|
||||
config INT_SOURCE
|
||||
int
|
||||
|
||||
config HEX_SOURCE
|
||||
hex
|
||||
|
||||
# 'hex' reference from 'int'
|
||||
|
||||
config INT_DEFAULT_HEX
|
||||
int
|
||||
default HEX_SOURCE
|
||||
|
||||
config INT_RANGE_HEX
|
||||
int
|
||||
range HEX_SOURCE 1
|
||||
|
||||
# A hex symbol must not reference an int symbol
|
||||
|
||||
config HEX_DEFAULT_INT
|
||||
hex
|
||||
default INT_SOURCE
|
||||
|
||||
config HEX_RANGE_INT
|
||||
hex
|
||||
range INT_SOURCE 0x1
|
||||
|
||||
# Referencing the same type is valid
|
||||
|
||||
config INT_FROM_INT
|
||||
int
|
||||
default INT_SOURCE
|
||||
|
||||
config HEX_FROM_HEX
|
||||
hex
|
||||
range 0 HEX_SOURCE
|
||||
9
scripts/kconfig/tests/err_num_mismatch/__init__.py
Normal file
9
scripts/kconfig/tests/err_num_mismatch/__init__.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# SPDX-License-Identifier: GPL-2.0
|
||||
"""
|
||||
Reject direct references ('default' or 'range') between int and hex options.
|
||||
"""
|
||||
|
||||
|
||||
def test(conf):
|
||||
assert conf.olddefconfig() == 1
|
||||
assert conf.stderr_matches('expected_stderr')
|
||||
4
scripts/kconfig/tests/err_num_mismatch/expected_stderr
Normal file
4
scripts/kconfig/tests/err_num_mismatch/expected_stderr
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Kconfig:14: error: 'HEX_SOURCE' is an invalid value for 'integer'
|
||||
Kconfig:18: error: 'HEX_SOURCE' is an invalid value for 'integer'
|
||||
Kconfig:24: error: 'INT_SOURCE' is an invalid value for 'hex'
|
||||
Kconfig:28: error: 'INT_SOURCE' is an invalid value for 'hex'
|
||||
Loading…
Reference in New Issue
Block a user