Skip to content

parser: reject [ and ] in %option= values to prevent m4-quote injection#729

Open
MarkLee131 wants to merge 1 commit into
westes:masterfrom
MarkLee131:fix/m4-quote-filter-option-values
Open

parser: reject [ and ] in %option= values to prevent m4-quote injection#729
MarkLee131 wants to merge 1 commit into
westes:masterfrom
MarkLee131:fix/m4-quote-filter-option-values

Conversation

@MarkLee131
Copy link
Copy Markdown

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) during flex 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.

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.
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.

prefix= is filtered for [/] but the other m4-passing %option values aren't

1 participant