Skip to content

Commit

Permalink
Abort expression parsing after encountering a maximum of 10 errors
Browse files Browse the repository at this point in the history
Fixes #19480

(cherry-picked from 3c8b156)
  • Loading branch information
nyalldawson committed Jul 30, 2018
1 parent a1ef59c commit 23b76ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/core/qgsexpressionparser.yy
Expand Up @@ -31,6 +31,9 @@
// don't redeclare malloc/free
#define YYINCLUDED_STDLIB_H 1

// maximum number of errors encountered before parser aborts
#define MAX_ERRORS 10

struct expression_parser_context;
#include "qgsexpressionparser.hpp"

Expand Down Expand Up @@ -177,7 +180,10 @@ root: expression { parser_ctx->rootNode = $1; }
| error expression
{
delete $2;
yyerrok;
if ( parser_ctx->parserErrors.count() < MAX_ERRORS )
yyerrok;
else
YYABORT;
}
;

Expand Down
8 changes: 8 additions & 0 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -287,6 +287,14 @@ class TestQgsExpression: public QObject
QCOMPARE( exp.parserErrors().first().lastColumn, lastColumn );
}

void max_errors()
{
QgsExpression e( "wkt_geom&#x9;OBJECTID&#x9;id&#x9;a&#x9;b&#x9;c&#x9;d&#x9;e&#x9;f&#x9;g&#x9;h&#x9;i&#x9;j&#x9;k&#x9;l&#x9;m&#x9;n&#x9;o&#x9;p&#x9;q&#x9;r&#x9;" );
QVERIFY( e.hasParserError() );
// want parsing to abort after a maximum of 10 errors
QCOMPARE( e.parserErrors().count(), 10 );
}

void parsing_with_locale()
{
// check that parsing of numbers works correctly even when using some other locale
Expand Down

0 comments on commit 23b76ef

Please sign in to comment.