parser: reject [ and ] in %option= values to prevent m4-quote injection#729
Open
MarkLee131 wants to merge 1 commit into
Open
parser: reject [ and ] in %option= values to prevent m4-quote injection#729MarkLee131 wants to merge 1 commit into
MarkLee131 wants to merge 1 commit into
Conversation
The OPTION-state quoted-string rule at src/scan.l:480 accepts arbitrary non-quote, non-newline bytes, including [ and ]. Those values are later interpolated into m4 input as `m4_define([[NAME]],[[%s]])` in filter.c and main.c. A `]]` inside the value breaks out of m4's quoting and lets a .l file run arbitrary m4 builtins (m4_syscmd / m4_esyscmd / m4_include) during `flex foo.l`. PR westes#81 (7528bc0, 2016) added ESCAPED_QSTART / ESCAPED_QEND escaping for action and code-block contexts, but the same fix was never extended to %option= values. Only `prefix=` had a brackets-rejection guard. Apply the same guard to all eight %option= values that flow into m4: outfile, header-file, yydecl, yyclass, extra-type, pre-action, post-action, yyterminate. (prefix already had the check; the helper replaces the inline one.) Verified each value rejects [ and ] with a clear error message, and a normal .l file still builds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #728:
The OPTION-state quoted-string rule at src/scan.l:480 accepts arbitrary non-quote, non-newline bytes, including [ and ]. Those values are later interpolated into m4 input as
m4_define([[NAME]],[[%s]])in filter.c and main.c. A]]inside the value breaks out of m4's quoting and lets a .l file run arbitrary m4 builtins (m4_syscmd / m4_esyscmd / m4_include) duringflex foo.l.PR #81 (7528bc0, 2016) added ESCAPED_QSTART / ESCAPED_QEND escaping for action and code-block contexts, but the same fix was never extended to %option= values. Only
prefix=had a brackets-rejection guard.Apply the same guard to all eight %option= values that flow into m4: outfile, header-file, yydecl, yyclass, extra-type, pre-action, post-action, yyterminate. (prefix already had the check; the helper replaces the inline one.)
Verified each value rejects [ and ] with a clear error message, and a normal .l file still builds.