Browse code

cfg parser: segfault on case RE parse error fix

Reported-by: Klaus Feichtinger klaus.feichtinger gmx net

Andrei Pelinescu-Onciul authored on 24/02/2010 14:13:12
Showing 1 changed files
... ...
@@ -2277,12 +2277,14 @@ if_cmd:
2277 2277
 
2278 2278
 ct_rval: rval_expr {
2279 2279
 			$$=0;
2280
-			if (!rve_is_constant($1)){
2280
+			if ($1 && !rve_is_constant($1)){
2281 2281
 				yyerror("constant expected");
2282
+				YYERROR;
2282 2283
 			/*
2283
-			} else if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
2284
+			} else if ($1 &&
2285
+						!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
2284 2286
 				yyerror("invalid expression (bad type)");
2285
-			}else if (i_tmp!=RV_INT){
2287
+			}else if ($1 && i_tmp!=RV_INT){
2286 2288
 				yyerror("invalid expression type, int expected\n");
2287 2289
 			*/
2288 2290
 			}else
... ...
@@ -2292,28 +2294,28 @@ ct_rval: rval_expr {
2292 2292
 single_case:
2293 2293
 	CASE ct_rval COLON actions {
2294 2294
 		$$=0;
2295
-		if ($2==0) yyerror ("bad case label");
2295
+		if ($2==0) { yyerror ("bad case label"); YYERROR; }
2296 2296
 		else if ((($$=mk_case_stm($2, 0, $4, &i_tmp))==0) && (i_tmp==-10)){
2297 2297
 				YYABORT;
2298 2298
 		}
2299 2299
 	}
2300 2300
 | CASE SLASH ct_rval COLON actions {
2301 2301
 		$$=0;
2302
-		if ($3==0) yyerror ("bad case label");
2302
+		if ($3==0) { yyerror ("bad case label"); YYERROR; }
2303 2303
 		else if ((($$=mk_case_stm($3, 1, $5, &i_tmp))==0) && (i_tmp==-10)){
2304 2304
 				YYABORT;
2305 2305
 		}
2306 2306
 	}
2307 2307
 	| CASE ct_rval COLON {
2308 2308
 		$$=0;
2309
-		if ($2==0) yyerror ("bad case label");
2309
+		if ($2==0) { yyerror ("bad case label"); YYERROR; }
2310 2310
 		else if ((($$=mk_case_stm($2, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
2311 2311
 				YYABORT;
2312 2312
 		}
2313 2313
 	}
2314 2314
 	| CASE SLASH ct_rval COLON {
2315 2315
 		$$=0;
2316
-		if ($3==0) yyerror ("bad case label");
2316
+		if ($3==0) { yyerror ("bad regex case label"); YYERROR; }
2317 2317
 		else if ((($$=mk_case_stm($3, 1, 0, &i_tmp))==0) && (i_tmp==-10)){
2318 2318
 				YYABORT;
2319 2319
 		}
... ...
@@ -2328,7 +2330,10 @@ single_case:
2328 2328
 				YYABORT;
2329 2329
 		}
2330 2330
 	}
2331
-	| CASE error { $$=0; yyerror("bad case label"); }
2331
+	| CASE error COLON actions { $$=0; yyerror("bad case label"); }
2332
+	| CASE SLASH error COLON actions { $$=0; yyerror("bad case regex label"); }
2333
+	| CASE error COLON { $$=0; yyerror("bad case label"); }
2334
+	| CASE SLASH error COLON { $$=0; yyerror("bad case regex label"); }
2332 2335
 	| CASE ct_rval COLON error { $$=0; yyerror ("bad case body"); }
2333 2336
 ;
2334 2337
 case_stms: