Skip to content

ls-config: fix stack overflow printing large floats in read_config - #306

Merged
hyperrealm merged 1 commit into
hyperrealm:masterfrom
affan-arch:ls-config-float-buffer
Oct 30, 2026
Merged

hyperrealm merged 1 commit into
hyperrealm:masterfrom
affan-arch:ls-config-float-buffer

Conversation

@affan-arch

Copy link
Copy Markdown
Contributor

read_config() prints floats with sprintf(buffer, "%f", ...) into a 256-byte stack buffer, and %f never falls back to exponent notation, so a config value like x = 1e300; (as a scalar, array element or list element) expands to 308 chars and overruns it; the buffer now fits any double (-DBL_MAX needs 318 bytes), the three float writes use snprintf(), and test_float_overflow.c covers all three paths the same way test_sinp_overflow.c does.

read_config() printed float values with sprintf("%f") into a 256-byte
stack buffer. %f never switches to exponent notation, so a value such as
1e300 in the config file expands to 308 characters and overruns it. This
hit scalar floats as well as float elements of arrays and lists.

Grow the buffer so any double fits (-DBL_MAX needs 318 bytes) and bound
the three float writes with snprintf(). test_float_overflow.c reads each
case back through read_config() and aborts under ASan without the fix.
@hyperrealm
hyperrealm merged commit 2afe438 into hyperrealm:master Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants