Skip to content

Commit 23b76ef

Browse files
committedJul 30, 2018
Abort expression parsing after encountering a maximum of 10 errors
Fixes #19480 (cherry-picked from 3c8b156)
1 parent a1ef59c commit 23b76ef

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

‎src/core/qgsexpressionparser.yy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
// don't redeclare malloc/free
3232
#define YYINCLUDED_STDLIB_H 1
3333

34+
// maximum number of errors encountered before parser aborts
35+
#define MAX_ERRORS 10
36+
3437
struct expression_parser_context;
3538
#include "qgsexpressionparser.hpp"
3639

@@ -177,7 +180,10 @@ root: expression { parser_ctx->rootNode = $1; }
177180
| error expression
178181
{
179182
delete $2;
180-
yyerrok;
183+
if ( parser_ctx->parserErrors.count() < MAX_ERRORS )
184+
yyerrok;
185+
else
186+
YYABORT;
181187
}
182188
;
183189

‎tests/src/core/testqgsexpression.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ class TestQgsExpression: public QObject
287287
QCOMPARE( exp.parserErrors().first().lastColumn, lastColumn );
288288
}
289289

290+
void max_errors()
291+
{
292+
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;" );
293+
QVERIFY( e.hasParserError() );
294+
// want parsing to abort after a maximum of 10 errors
295+
QCOMPARE( e.parserErrors().count(), 10 );
296+
}
297+
290298
void parsing_with_locale()
291299
{
292300
// check that parsing of numbers works correctly even when using some other locale

0 commit comments

Comments
 (0)
Please sign in to comment.