Skip to content

Commit

Permalink
sql: Add sanity check for PLSQL inquiry directive size
Browse files Browse the repository at this point in the history
$$ typed anywhere in the code, e.g. by accident, makes the rest of the
code appear to the parser as a dollar-quoted string which can be thousands
of bytes long. In this case lookupCaseKeyword() is called repeatedly on
this ever increasing string which consumes a lot of time and makes the
parser appear completely unresponsive for large files.

This patch adds a sanity check to perform lookupCaseKeyword() only for
strings of length smaller than 30 (currently the longest inquiry directive
keyword is 21 characters long so there should be some safe extra margin
even for longer keywords if added in the future).

Fixes #3647.
  • Loading branch information
techee committed Mar 13, 2023
1 parent 8c19c47 commit c3b0324
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions parsers/sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,8 @@ static tokenType parseDollarQuote (vString *const string, const int delimiter, i
{
vStringPut (string, c);
if (empty_tag
&& (KEYWORD_inquiry_directive == lookupCaseKeyword (vStringValue (string),
Lang_sql)
&& ((string->length < 30 && KEYWORD_inquiry_directive == lookupCaseKeyword (vStringValue (string),
Lang_sql))
|| isCCFlag(vStringValue (string))))
{
/* PL/SQL inquiry directives */
Expand Down

0 comments on commit c3b0324

Please sign in to comment.