[SR-Dev] git:andrei/type_conversion: script parsing: fix bug in expression error checking

Andrei Pelinescu-Onciul andrei at iptel.org
Wed Apr 29 14:03:57 CEST 2009


Module: sip-router
Branch: andrei/type_conversion
Commit: 36d4ed7ce18f025bc69fb24e1820bcb8ec56984f
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=36d4ed7ce18f025bc69fb24e1820bcb8ec56984f

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Wed Apr 29 14:02:16 2009 +0200

script parsing: fix bug in expression error checking

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

---

 cfg.y |   28 +++++++++++++++++++---------
 1 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/cfg.y b/cfg.y
index df3056d..f703238 100644
--- a/cfg.y
+++ b/cfg.y
@@ -1565,7 +1565,10 @@ send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
 
 exp:	rval_expr
 		{
-			if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
+			if ($1==0){
+				yyerror("invalid expression");
+				$$=0;
+			}else if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
 				yyerror("invalid expression");
 				$$=0;
 			}else if (i_tmp!=RV_INT && i_tmp!=RV_NONE){
@@ -2220,9 +2223,9 @@ rval: intno			{$$=mk_rve_rval(RV_INT, (void*)$1); }
 	| fcmd				{$$=mk_rve_rval(RV_ACTION_ST, $1); }
 	| exp_elem { $$=mk_rve_rval(RV_BEXPR, $1); }
 	| LBRACE actions RBRACE	{$$=mk_rve_rval(RV_ACTION_ST, $2); }
-	| LBRACE error RBRACE	{ yyerror("bad command block"); }
+	| LBRACE error RBRACE	{ $$=0; yyerror("bad command block"); }
 	| LPAREN assign_action RPAREN	{$$=mk_rve_rval(RV_ACTION_ST, $2); }
-	| LPAREN error RPAREN	{ yyerror("bad expression"); }
+	| LPAREN error RPAREN	{ $$=0; yyerror("bad expression"); }
 	;
 
 
@@ -2240,10 +2243,11 @@ rve_op:		PLUS		{ $$=RVE_PLUS_OP; }
 */
 
 rval_expr: rval						{ $$=$1;
-											if ($$==0){
+										/*	if ($$==0){
 												yyerror("out of memory\n");
 												YYABORT;
 											}
+											*/
 									}
 		| rve_un_op %prec NOT rval_expr	{$$=mk_rve1($1, $2); }
 		| rval_expr PLUS rval_expr		{$$=mk_rve2(RVE_PLUS_OP, $1, $3); }
@@ -2261,7 +2265,7 @@ rval_expr: rval						{ $$=$1;
 		| STRLEN LPAREN rval_expr RPAREN { $$=mk_rve1(RVE_STRLEN_OP, $3);}
 		| STREMPTY LPAREN rval_expr RPAREN {$$=mk_rve1(RVE_STREMPTY_OP, $3);}
 		| DEFINED rval_expr				{ $$=mk_rve1(RVE_DEFINED_OP, $2);}
-		| rve_un_op %prec NOT error		{ yyerror("bad expression"); }
+		| rve_un_op %prec NOT error		{ $$=0; yyerror("bad expression"); }
 		| rval_expr PLUS error			{ yyerror("bad expression"); }
 		| rval_expr MINUS error			{ yyerror("bad expression"); }
 		| rval_expr STAR error			{ yyerror("bad expression"); }
@@ -2274,9 +2278,9 @@ rval_expr: rval						{ $$=$1;
 			{ yyerror("bad expression"); }
 		| rval_expr LOG_AND error		{ yyerror("bad expression"); }
 		| rval_expr LOG_OR error		{ yyerror("bad expression"); }
-		| STRLEN LPAREN error RPAREN	{ yyerror("bad expression"); }
-		| STREMPTY LPAREN error RPAREN	{ yyerror("bad expression"); }
-		| DEFINED error					{ yyerror("bad expression"); }
+		| STRLEN LPAREN error RPAREN	{ $$=0; yyerror("bad expression"); }
+		| STREMPTY LPAREN error RPAREN	{ $$=0; yyerror("bad expression"); }
+		| DEFINED error					{ $$=0; yyerror("bad expression"); }
 		;
 
 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,
 	
 	if ((rve1==0) || (rve2==0))
 		return 0;
+	bad_rve=0;
+	bad_t=0;
+	exp_t=0;
 	cfg_pos_join(&pos, &rve1->fpos, &rve2->fpos);
 	ret=mk_rval_expr2(op, rve1, rve2, &pos);
 	if (ret && (rve_check_type(&type, ret, &bad_rve, &bad_t, &exp_t)!=1)){
-		yyerror_at(&pos, "bad expression: type mismatch:"
+		if (bad_rve)
+			yyerror_at(&pos, "bad expression: type mismatch:"
 						" %s instead of %s at (%d,%d)",
 						rval_type_name(bad_t), rval_type_name(exp_t),
 						bad_rve->fpos.s_line, bad_rve->fpos.s_col);
+		else
+			yyerror("BUG: unexpected null \"bad\" expression\n");
 	}
 	return ret;
 }




More information about the sr-dev mailing list