Skip to content

scanner: don't let an open comment or string leak out of an include file - #316

Merged
hyperrealm merged 1 commit into
hyperrealm:masterfrom
affan-arch:include-eof-state
Nov 21, 2026
Merged

hyperrealm merged 1 commit into
hyperrealm:masterfrom
affan-arch:include-eof-state

Conversation

@affan-arch

Copy link
Copy Markdown
Contributor

Repro: put @include "frag.cfg" in a file, followed by admin = false;, and end frag.cfg with color = "blue"; /* notes. config_read_file() returns true and admin is simply gone.
Cause: the <<EOF>> rule moves on to the next include file, or back to the parent, without resetting the start condition, so an open block comment, string or @include path carries on into the next file. A # comment on the last line with no trailing newline also eats whatever follows on the @include line, or the first line of the next file in an include list.
Fix: end a line comment at end of file, and fail an included file that ends in any other state with "unexpected end of include file", reported against that file. Top-level files behave as before, so existing configs that end in an open comment still load; happy to make those strict too if you'd prefer. scanner.c/scanner.h match flex 2.6.4 output, and the new IncludeUnterminated test fails without the fix.

The <<EOF>> rule moves on to the next file of an @include list, or back
to the including file, without resetting the start condition. So an
included file that ends inside a /* comment, a string or an @include
path keeps scanning the next file in that state, and a block comment
silently drops every setting after the @include while the read still
succeeds.

End a line comment at the end of its file, and fail an included file
that ends in any other state with "unexpected end of include file".
Top-level files are unchanged.
@hyperrealm
hyperrealm merged commit 5fe7f92 into hyperrealm:master Nov 21, 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