Commit debe772
committed
[preprocessor] Fix crash/hang on truncated callable macro invocation
GenerateBypassWhiteSpaces dereferences the stream iterator (**iterator) with no
end guard, relying on every stream ending in a kept EOF token. The streams
re-lexed for macro expansion in ExpandText, ExpandMacro, HandleInclude and the
standalone tool strip the EOF (loop stops on !isEOF()), so a callable macro
invocation truncated at end-of-stream (e.g. `define A(x) hello `A followed by
`A(1)) makes the streamer return the view's end() iterator and the deref reads
past the end -> SIGSEGV. An included file ending in a callable macro crashes the
same way; a '(' with no ')' spins forever.
Restore the kept-EOF sentinel on each re-lexed stream so the whitespace-skip
loop stops at EOF and callers return a diagnostic instead of dereferencing past
the end: append the EOF sentinel in all four stream builders; break on it in the
two token-pulling loops so it is not forwarded; skip it when splicing an included
child stream into the parent; and break on EOF in the argument-scanning loop
(the one caller that did not handle a mid-scan EOF, which otherwise hangs on a
'(' without ')'). Also record the "callable macro without ()" error in
preprocess_data_.errors instead of silently swallowing it (requires making
ConsumeAndParseMacroCall non-static).
Adds TruncatedCallableMacroDoesNotCrash. Existing preprocessor and analyzer test
suites pass. Unbounded macro self-recursion is a separate pre-existing bug and
is not addressed here.
Signed-off-by: Eylon Krause <eylon1909@gmail.com>1 parent 873f559 commit debe772
4 files changed
Lines changed: 50 additions & 4 deletions
File tree
- verible/verilog
- preprocessor
- tools/preprocessor
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
248 | 251 | | |
249 | 252 | | |
250 | 253 | | |
251 | 254 | | |
252 | 255 | | |
| 256 | + | |
253 | 257 | | |
254 | 258 | | |
255 | 259 | | |
| |||
342 | 346 | | |
343 | 347 | | |
344 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
345 | 353 | | |
346 | 354 | | |
347 | 355 | | |
| |||
352 | 360 | | |
353 | 361 | | |
354 | 362 | | |
| 363 | + | |
355 | 364 | | |
356 | 365 | | |
357 | 366 | | |
| |||
396 | 405 | | |
397 | 406 | | |
398 | 407 | | |
| 408 | + | |
| 409 | + | |
399 | 410 | | |
400 | 411 | | |
401 | 412 | | |
| |||
407 | 418 | | |
408 | 419 | | |
409 | 420 | | |
| 421 | + | |
410 | 422 | | |
411 | 423 | | |
412 | 424 | | |
| |||
635 | 647 | | |
636 | 648 | | |
637 | 649 | | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
638 | 653 | | |
639 | 654 | | |
640 | 655 | | |
| |||
657 | 672 | | |
658 | 673 | | |
659 | 674 | | |
660 | | - | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
661 | 678 | | |
| 679 | + | |
662 | 680 | | |
663 | 681 | | |
664 | 682 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
168 | | - | |
169 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
170 | 172 | | |
171 | 173 | | |
172 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1033 | 1033 | | |
1034 | 1034 | | |
1035 | 1035 | | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
1036 | 1061 | | |
1037 | 1062 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
0 commit comments