mruby · GitHub

Commit 510ebd7

matzclaude

and

committed

mruby-compiler: terminate parsing early after too many errors

When parsing malformed input with many syntax errors (e.g., via eval with a long garbage string), the parser would continue until the end of input, causing long execution times. Add an early termination check in the lexer that returns EOF once the error count exceeds 10 (same as error_buffer size). This prevents DoS from inputs like eval("garbage" * 1000). Co-authored-by: Claude <noreply@anthropic.com>

2 files changed

Lines changed: 2361 additions & 2286 deletions

File tree

  • mrbgems/mruby-compiler/core

Lines changed: 5 additions & 0 deletions

Original file line numberDiff line numberDiff line change

@@ -6120,6 +6120,11 @@ parser_yylex(parser_state *p)

61206120

enum mrb_lex_state_enum last_state;

61216121

int token_column;

61226122
6123+

/* Early termination if too many errors - prevents DoS from malformed input */

6124+

if (p->nerr > 10) {

6125+

return 0; /* EOF */

6126+

}

6127+
61236128

if (p->lex_strterm) {

61246129

if (is_strterm_type(p, STR_FUNC_HEREDOC)) {

61256130

if (p->parsing_heredoc != NULL)

Read the original on github.com ↗