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 2294
 single_case:
2293 2295
 	CASE ct_rval COLON actions {
2294 2296
 		$$=0;
2295
-		if ($2==0) yyerror ("bad case label");
2297
+		if ($2==0) { yyerror ("bad case label"); YYERROR; }
2296 2298
 		else if ((($$=mk_case_stm($2, 0, $4, &i_tmp))==0) && (i_tmp==-10)){
2297 2299
 				YYABORT;
2298 2300
 		}
2299 2301
 	}
2300 2302
 | CASE SLASH ct_rval COLON actions {
2301 2303
 		$$=0;
2302
-		if ($3==0) yyerror ("bad case label");
2304
+		if ($3==0) { yyerror ("bad case label"); YYERROR; }
2303 2305
 		else if ((($$=mk_case_stm($3, 1, $5, &i_tmp))==0) && (i_tmp==-10)){
2304 2306
 				YYABORT;
2305 2307
 		}
2306 2308
 	}
2307 2309
 	| CASE ct_rval COLON {
2308 2310
 		$$=0;
2309
-		if ($2==0) yyerror ("bad case label");
2311
+		if ($2==0) { yyerror ("bad case label"); YYERROR; }
2310 2312
 		else if ((($$=mk_case_stm($2, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
2311 2313
 				YYABORT;
2312 2314
 		}
2313 2315
 	}
2314 2316
 	| CASE SLASH ct_rval COLON {
2315 2317
 		$$=0;
2316
-		if ($3==0) yyerror ("bad case label");
2318
+		if ($3==0) { yyerror ("bad regex case label"); YYERROR; }
2317 2319
 		else if ((($$=mk_case_stm($3, 1, 0, &i_tmp))==0) && (i_tmp==-10)){
2318 2320
 				YYABORT;
2319 2321
 		}
... ...
@@ -2328,7 +2330,10 @@ single_case:
2328 2330
 				YYABORT;
2329 2331
 		}
2330 2332
 	}
2331
-	| CASE error { $$=0; yyerror("bad case label"); }
2333
+	| CASE error COLON actions { $$=0; yyerror("bad case label"); }
2334
+	| CASE SLASH error COLON actions { $$=0; yyerror("bad case regex label"); }
2335
+	| CASE error COLON { $$=0; yyerror("bad case label"); }
2336
+	| CASE SLASH error COLON { $$=0; yyerror("bad case regex label"); }
2332 2337
 	| CASE ct_rval COLON error { $$=0; yyerror ("bad case body"); }
2333 2338
 ;
2334 2339
 case_stms: