Skip to content

lib: fix stale error_file pointer and error line on config re-read - #308

Merged
hyperrealm merged 1 commit into
hyperrealm:masterfrom
affan-arch:config-read-reset-error-state
Nov 5, 2026
Merged

hyperrealm merged 1 commit into
hyperrealm:masterfrom
affan-arch:config-read-reset-error-state

Conversation

@affan-arch

Copy link
Copy Markdown
Contributor

__config_read() never reset the error fields, so on a reused config_t a stale error_text makes libconfig_yyerror() skip the next parse error (it reports the previous read's line and message), and after a failed read followed by a successful one config_error_file() still points into the filenames vector that config_clear() just freed, which the usual fprintf("%s:%d - %s", config_error_file(&cfg), ...) report then reads on the next I/O error (ASan: heap-use-after-free, freed in config_clear() via __config_read()); config_clear() now drops error_file along with the storage it points into, each read starts from a clean error state, and the new ErrorStateOnReread test fails without the fix.

__config_read() never cleared error_text, error_line or error_type, and
config_clear() freed config->filenames without clearing error_file,
which points into that vector.

On a config_t that is read more than once, a failed config_read_file()
followed by a successful one leaves config_error_file() pointing at a
freed string. A later I/O error doesn't touch error_file, so the usual
fprintf("%s:%d - %s", config_error_file(&cfg), ...) report reads freed
memory. The stale error_text also makes libconfig_yyerror() return
early, so the next parse error is reported with the previous read's
line and message.

Clear error_file in config_clear() together with the storage it points
into, start each read with a clean error state, and clear the file and
line on the config_read_file() I/O-error path. ErrorStateOnReread
covers both cases and fails without the fix.
@hyperrealm
hyperrealm merged commit 780640f into hyperrealm:master Nov 5, 2026
5 checks passed
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