preprocessor: stop macro-argument scan on an unexpected/EOF token ConsumeAndParseMacroCall's `while (parameters_size > 0)` argument loop only handled MacroArg, ',' and ')'. An unterminated macro call (e.g. `\`FOO(` at end of file) leaves the current token as EOF, which matches none of the three branches, so neither token_iter nor parameters_size advances and the loop spins forever -- a hang when linting or serving a truncated/untrusted .sv (both reach this via AnalyzeAutomaticPreprocessFallback with expand_macros=true). Break out on any other token; the existing trailing loop already back-fills the remaining parameters with default TokenInfo, the same terminal state an early ')' produces. Note: a related path (GenerateBypassWhiteSpaces dereferencing an exhausted generator when a macro-expansion token sequence lacks a trailing EOF sentinel) can crash on similar input; happy to follow up separately. Signed-off-by: Eylon Krause <eylon1909@gmail.com>
diff --git a/verible/verilog/preprocessor/verilog-preprocess.cc b/verible/verilog/preprocessor/verilog-preprocess.cc index 2f77111..d8f5f5b 100644 --- a/verible/verilog/preprocessor/verilog-preprocess.cc +++ b/verible/verilog/preprocessor/verilog-preprocess.cc
@@ -268,6 +268,12 @@ if ((*token_iter)->text() == ")") { break; } + // Any other token -- in particular the EOF token from an unterminated + // macro call -- would otherwise leave token_iter and parameters_size + // unchanged and spin this loop forever. Stop scanning; the loop below + // back-fills the remaining parameters with default TokenInfo (the same + // terminal state produced by an early ')'). + break; } if (parameters_size > 0) { while (parameters_size--) {