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 2, 2023
1 parent 4c90db0 commit 7d8742b
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 @@ -791,8 +791,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 7d8742b

Please sign in to comment.