[SR-Dev] git:master: Importing kamailio fixes into the sip-router version of re.c

Jan Janak jan at iptel.org
Sun Mar 8 04:43:57 CET 2009


Module: sip-router
Branch: master
Commit: b23b15b9977c0f6d7da955d335eaacbe282df12b
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b23b15b9977c0f6d7da955d335eaacbe282df12b

Author: Jan Janak <jan at iptel.org>
Committer: Jan Janak <jan at iptel.org>
Date:   Sun Mar  8 04:32:34 2009 +0100

Importing kamailio fixes into the sip-router version of re.c

This patch imports the following two fixes:
 *  bug fixed in multiple matching on complete lines.
    Closes bug #1819248.
    Credits go to Alexander Bergolth (SF bergolth)
    (svn commit id 3096)

 * non-critical bug fixed - invalid regexps may lead to infinite matches
   and finally to memory starvation.
   Reported to Klaus Darilion <klaus.mailinglists at pernau.at>
   (svn commit id 1039)

---

 re.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/re.c b/re.c
index 21a0a5a..7f1dc23 100644
--- a/re.c
+++ b/re.c
@@ -483,18 +483,20 @@ struct replace_lst* subst_run(struct subst_expr* se, const char* input,
 		DBG("subst_run: running. r=%d\n", r);
 		/* subst */
 		if (r==0){ /* != REG_NOMATCH */
-			/* change eflags, not to match any more at string start */
-			eflags|=REG_NOTBOL;
+			if (pmatch[0].rm_so==-1) {
+				ERR("subst_run: Unknown offset?\n");
+				goto error;
+			}
+			if (pmatch[0].rm_so==pmatch[0].rm_eo) {
+				ERR("subst_run: Matched string is empty, invalid regexp?\n");
+				goto error;
+			}
 			*crt=pkg_malloc(sizeof(struct replace_lst));
 			if (*crt==0){
 				LOG(L_ERR, "ERROR: subst_run: out of mem (crt)\n");
 				goto error;
 			}
 			memset(*crt, 0, sizeof(struct replace_lst));
-			if (pmatch[0].rm_so==-1){
-				LOG(L_ERR, "ERROR: subst_run: unknown offset?\n");
-				goto error;
-			}
 			(*crt)->offset=pmatch[0].rm_so+(int)(p-input);
 			(*crt)->size=pmatch[0].rm_eo-pmatch[0].rm_so;
 			DBG("subst_run: matched (%d, %d): [%.*s]\n",
@@ -507,6 +509,8 @@ struct replace_lst* subst_run(struct subst_expr* se, const char* input,
 			}
 			crt=&((*crt)->next);
 			p+=pmatch[0].rm_eo;
+			if (*(p-1) == '\n' || *(p-1) == '\r') eflags&=~REG_NOTBOL;
+			else eflags|=REG_NOTBOL;
 			cnt++;
 		}
 	}while((r==0) && se->replace_all);




More information about the sr-dev mailing list