Browse Source

core: ensure index of preprocessor directive conditions is not negative

- avoid accessing the array at negative index for else processing
Daniel-Constantin Mierla 6 years ago
parent
commit
8f6e826576
1 changed files with 11 additions and 1 deletions
  1. 11 1
      src/core/cfg.lex

+ 11 - 1
src/core/cfg.lex

@@ -1942,14 +1942,24 @@ static void pp_ifdef()
 
 static void pp_else()
 {
+	if(pp_sptr==0) {
+		LM_WARN("invalid position for preprocessor directive 'else'"
+				" - at %s line %d\n", (finame)?finame:"cfg", line);
+		return;
+	}
 	pp_ifdef_stack[pp_sptr-1] ^= 1;
 	pp_update_state();
 }
 
 static void pp_endif()
 {
-	pp_sptr--;
 	pp_ifdef_level_update(-1);
+	if(pp_sptr==0) {
+		LM_WARN("invalid position for preprocessor directive 'else'"
+				" - at %s line %d\n", (finame)?finame:"cfg", line);
+		return;
+	}
+	pp_sptr--;
 	pp_update_state();
 }