Browse code

script parsing: fix bug in expression error checking

- fixed core dump when attempting to continuing script checking
after an expression parse error.

Andrei Pelinescu-Onciul authored on 29/04/2009 12:02:16
Showing 1 changed files
... ...
@@ -1565,7 +1565,10 @@ send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
1565 1565
 
1566 1566
 exp:	rval_expr
1567 1567
 		{
1568
-			if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
1568
+			if ($1==0){
1569
+				yyerror("invalid expression");
1570
+				$$=0;
1571
+			}else if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
1569 1572
 				yyerror("invalid expression");
1570 1573
 				$$=0;
1571 1574
 			}else if (i_tmp!=RV_INT && i_tmp!=RV_NONE){
... ...
@@ -2220,9 +2223,9 @@ rval: intno			{$$=mk_rve_rval(RV_INT, (void*)$1); }
2220 2220
 	| fcmd				{$$=mk_rve_rval(RV_ACTION_ST, $1); }
2221 2221
 	| exp_elem { $$=mk_rve_rval(RV_BEXPR, $1); }
2222 2222
 	| LBRACE actions RBRACE	{$$=mk_rve_rval(RV_ACTION_ST, $2); }
2223
-	| LBRACE error RBRACE	{ yyerror("bad command block"); }
2223
+	| LBRACE error RBRACE	{ $$=0; yyerror("bad command block"); }
2224 2224
 	| LPAREN assign_action RPAREN	{$$=mk_rve_rval(RV_ACTION_ST, $2); }
2225
-	| LPAREN error RPAREN	{ yyerror("bad expression"); }
2225
+	| LPAREN error RPAREN	{ $$=0; yyerror("bad expression"); }
2226 2226
 	;
2227 2227
 
2228 2228
 
... ...
@@ -2240,10 +2243,11 @@ rve_op:		PLUS		{ $$=RVE_PLUS_OP; }
2240 2240
 */
2241 2241
 
2242 2242
 rval_expr: rval						{ $$=$1;
2243
-											if ($$==0){
2243
+										/*	if ($$==0){
2244 2244
 												yyerror("out of memory\n");
2245 2245
 												YYABORT;
2246 2246
 											}
2247
+											*/
2247 2248
 									}
2248 2249
 		| rve_un_op %prec NOT rval_expr	{$$=mk_rve1($1, $2); }
2249 2250
 		| rval_expr PLUS rval_expr		{$$=mk_rve2(RVE_PLUS_OP, $1, $3); }
... ...
@@ -2261,7 +2265,7 @@ rval_expr: rval						{ $$=$1;
2261 2261
 		| STRLEN LPAREN rval_expr RPAREN { $$=mk_rve1(RVE_STRLEN_OP, $3);}
2262 2262
 		| STREMPTY LPAREN rval_expr RPAREN {$$=mk_rve1(RVE_STREMPTY_OP, $3);}
2263 2263
 		| DEFINED rval_expr				{ $$=mk_rve1(RVE_DEFINED_OP, $2);}
2264
-		| rve_un_op %prec NOT error		{ yyerror("bad expression"); }
2264
+		| rve_un_op %prec NOT error		{ $$=0; yyerror("bad expression"); }
2265 2265
 		| rval_expr PLUS error			{ yyerror("bad expression"); }
2266 2266
 		| rval_expr MINUS error			{ yyerror("bad expression"); }
2267 2267
 		| rval_expr STAR error			{ yyerror("bad expression"); }
... ...
@@ -2274,9 +2278,9 @@ rval_expr: rval						{ $$=$1;
2274 2274
 			{ yyerror("bad expression"); }
2275 2275
 		| rval_expr LOG_AND error		{ yyerror("bad expression"); }
2276 2276
 		| rval_expr LOG_OR error		{ yyerror("bad expression"); }
2277
-		| STRLEN LPAREN error RPAREN	{ yyerror("bad expression"); }
2278
-		| STREMPTY LPAREN error RPAREN	{ yyerror("bad expression"); }
2279
-		| DEFINED error					{ yyerror("bad expression"); }
2277
+		| STRLEN LPAREN error RPAREN	{ $$=0; yyerror("bad expression"); }
2278
+		| STREMPTY LPAREN error RPAREN	{ $$=0; yyerror("bad expression"); }
2279
+		| DEFINED error					{ $$=0; yyerror("bad expression"); }
2280 2280
 		;
2281 2281
 
2282 2282
 assign_action: lval assign_op  rval_expr	{ $$=mk_action($2, 2, LVAL_ST, $1, 
... ...
@@ -2904,13 +2908,19 @@ static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1,
2904 2904
 	
2905 2905
 	if ((rve1==0) || (rve2==0))
2906 2906
 		return 0;
2907
+	bad_rve=0;
2908
+	bad_t=0;
2909
+	exp_t=0;
2907 2910
 	cfg_pos_join(&pos, &rve1->fpos, &rve2->fpos);
2908 2911
 	ret=mk_rval_expr2(op, rve1, rve2, &pos);
2909 2912
 	if (ret && (rve_check_type(&type, ret, &bad_rve, &bad_t, &exp_t)!=1)){
2910
-		yyerror_at(&pos, "bad expression: type mismatch:"
2913
+		if (bad_rve)
2914
+			yyerror_at(&pos, "bad expression: type mismatch:"
2911 2915
 						" %s instead of %s at (%d,%d)",
2912 2916
 						rval_type_name(bad_t), rval_type_name(exp_t),
2913 2917
 						bad_rve->fpos.s_line, bad_rve->fpos.s_col);
2918
+		else
2919
+			yyerror("BUG: unexpected null \"bad\" expression\n");
2914 2920
 	}
2915 2921
 	return ret;
2916 2922
 }