diff options
author | Michal Čihař <michal@cihar.com> | 2017-07-12 15:34:22 +0200 |
---|---|---|
committer | Michal Čihař <michal@cihar.com> | 2017-07-12 15:34:45 +0200 |
commit | 65531ff4f3d8697e4b62db3bb3893a264c234251 (patch) | |
tree | f3a6b3714e16857ab6bfd6dc218f80f82858a7bb /src | |
parent | 5aab642e247331e00a73c2ad892ead41205c5a30 (diff) | |
download | sql-parser-65531ff4f3d8697e4b62db3bb3893a264c234251.zip sql-parser-65531ff4f3d8697e4b62db3bb3893a264c234251.tar.gz sql-parser-65531ff4f3d8697e4b62db3bb3893a264c234251.tar.bz2 |
Correctly handle incomplete statements
Fixes https://github.com/phpmyadmin/phpmyadmin/issues/13485
Signed-off-by: Michal Čihař <michal@cihar.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/Statement.php | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/Statement.php b/src/Statement.php index b59e758..ab554c3 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -312,7 +312,7 @@ abstract class Statement } // Checking if this is the beginning of a clause. - if (!empty(Parser::$KEYWORD_PARSERS[$token->value])) { + if (!empty(Parser::$KEYWORD_PARSERS[$token->value]) && $list->idx < $list->count) { $class = Parser::$KEYWORD_PARSERS[$token->value]['class']; $field = Parser::$KEYWORD_PARSERS[$token->value]['field']; if (!empty(Parser::$KEYWORD_PARSERS[$token->value]['options'])) { @@ -372,6 +372,11 @@ abstract class Statement // Parsing this keyword. if ($class !== null) { + // We can't parse keyword at the end of statement + if ($list->idx >= $list->count) { + $parser->error('Keyword at end of statement.', $token); + continue; + } ++$list->idx; // Skipping keyword or last option. $this->$field = $class::parse($parser, $list, $options); } |