Blob Blame Raw
From: Razvan Crainea <razvan@opensips.org>
Date: Thu, 1 Feb 2018 17:27:00 +0200
Subject: [PATCH] cfg: fix error reporting for unenclosed scriptvars

(cherry picked from commit adfc62b55cc2ada7ccac78bdaeab3bbdd47e5abf)

diff --git a/cfg.lex b/cfg.lex
index 0fb1804a1..1b3e74431 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -722,15 +722,15 @@ IMPORTFILE      "import_file"
 <INITIAL>{ANY}	{ count(); return ANY; }
 <INITIAL>{SLASH}	{ count(); return SLASH; }
 
-<INITIAL>{SCRIPTVAR_START} { count(); np=0; state=SCRIPTVAR_S;
+<INITIAL>{SCRIPTVAR_START} { np=0; state=SCRIPTVAR_S;
 								svar_tlen = yyleng;
 								yymore();
 								BEGIN(SCRIPTVARS);
 							}
-<SCRIPTVARS>{LPAREN} { count(); np++; yymore(); svar_tlen = yyleng; }
+<SCRIPTVARS>{LPAREN} { np++; yymore(); svar_tlen = yyleng; }
 <SCRIPTVARS>{RPAREN} {
-			count();
 			if(np==0 || np==1) {
+				count();
 				if(np==0)
 				{
 					addstr(&s_buf, yytext, yyleng-1);
@@ -752,8 +752,8 @@ IMPORTFILE      "import_file"
 			}
 		}
 <SCRIPTVARS>{WHITESPACE} {
-			count();
 			if(np==0) {
+				count();
 				addstr(&s_buf, yytext, yyleng-1);
 				unput(yytext[yyleng-1]);
 				yyleng--;
@@ -768,8 +768,8 @@ IMPORTFILE      "import_file"
 			}
 		}
 <SCRIPTVARS>{SEMICOLON}|{COMMA}|{ASSIGNOP}|{ARITHOP}|{BITOP}|{LOGOP} {
-						count();
 						if(np==0) {
+							count();
 							addstr(&s_buf, yytext, svar_tlen);
 							while(yyleng>svar_tlen) {
 								unput(yytext[yyleng-1]);
@@ -886,6 +886,10 @@ IMPORTFILE      "import_file"
 											LM_CRIT("unexpected EOF:"
 														"comment line open\n");
 											break;
+										case SCRIPTVAR_S:
+											LM_CRIT("unexpected EOF in"
+														" unclosed variable\n");
+											break;
 									}
 									if(oss_pop_yy_state()<0)
 										return 0;