aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/parse.c
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-05-24 02:01:21 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-05-26 17:04:29 +0200
commitbf28f6e2b80f81dd5ebd6431209712e0287f0587 (patch)
tree8dc56bf71d6513777fa8f70a422ae5523fd349df /parse.c
parent02510ae80084b9446d9afda779c0c4a3385eb22d (diff)
downloadsparse-dev-bf28f6e2b80f81dd5ebd6431209712e0287f0587.tar.gz
context: fix crashes while parsing '__context__;' or '__context__(;'
The expected syntax for the __context__ statement is: __context__(<inc/dec value>); or __context__(<context>, <inc/dec value>); The distinction between the two formats is made by checking if the expression is a PREOP with '(' as op and with an comma expression as inner expression. However, code like: __context__; or __context__(; crashes while trying to test the non-existing expression (after PREOP or after the comma expression). Fix this by testing if the expression is non-null before dereferencing it. Note: this fix has the merit to directly address the problem but doesn't let a diagnostic to be issued for the case __context__; which is considered as perfectly valid. The next patch will take care of this. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/parse.c b/parse.c
index 68cdeb22..42b3fd20 100644
--- a/parse.c
+++ b/parse.c
@@ -2339,8 +2339,10 @@ static struct token *parse_context_statement(struct token *token, struct stateme
{
stmt->type = STMT_CONTEXT;
token = parse_expression(token->next, &stmt->expression);
- if (stmt->expression->type == EXPR_PREOP
+ if (stmt->expression
+ && stmt->expression->type == EXPR_PREOP
&& stmt->expression->op == '('
+ && stmt->expression->unop
&& stmt->expression->unop->type == EXPR_COMMA) {
struct expression *expr;
expr = stmt->expression->unop;