[sr-dev] git:3.2: core/select: fixed @via... without header index

Daniel-Constantin Mierla miconda at gmail.com
Thu Jul 19 14:59:49 CEST 2012


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Thu May 31 14:44:19 2012 +0200

core/select: fixed @via... without header index

- reported by Iñaki Baz Castillo, fixes FS#138
(cherry picked from commit 511841b7bcdc7f5cc72775942ecf6b11525aad82)

---

 select.c      |    1 +
 select_core.c |   45 +++++++++++++++++++++++++++------------------
 2 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/select.c b/select.c
index f247687..36ae814 100644
--- a/select.c
+++ b/select.c
@@ -223,6 +223,7 @@ int parse_select (char** p, select_t** s)
 		ERR("parse_select: no free memory\n");
 		return -1;
 	}
+	memset(sel, 0, sizeof(select_t));
 	if (w_parse_select(p, sel)<0) {
 		pkg_free(sel);
 		return -2;
diff --git a/select_core.c b/select_core.c
index 42f6aff..49c5920 100644
--- a/select_core.c
+++ b/select_core.c
@@ -390,8 +390,9 @@ int select_via(str* res, select_t* s, struct sip_msg* msg)
 {
 	struct via_body *p = NULL;
 	
-	if (((s->n == 1) || (s->params[1].type == SEL_PARAM_STR)) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if ((s->n == 1) || (s->params[1].type == SEL_PARAM_STR)) {
+		if (parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	res->s=p->name.s;
 	res->len=p->bsize;
@@ -404,8 +405,9 @@ int select_via_name(str* res, select_t* s, struct sip_msg* msg)
 	struct via_body *p = NULL;
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if(parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	RETURN0_res(p->name);
 }
@@ -415,8 +417,9 @@ int select_via_version(str* res, select_t* s, struct sip_msg* msg)
 	struct via_body *p = NULL;
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if (parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	RETURN0_res(p->version);
 }
@@ -426,8 +429,9 @@ int select_via_transport(str* res, select_t* s, struct sip_msg* msg)
 	struct via_body *p = NULL;
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if(parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	RETURN0_res(p->transport);
 }
@@ -437,8 +441,9 @@ int select_via_host(str* res, select_t* s, struct sip_msg* msg)
 	struct via_body *p = NULL;
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if (parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	RETURN0_res(p->host);
 }
@@ -448,8 +453,9 @@ int select_via_port(str* res, select_t* s, struct sip_msg* msg)
 	struct via_body *p = NULL;
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if (parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	RETURN0_res(p->port_str);
 }
@@ -459,8 +465,9 @@ int select_via_comment(str* res, select_t* s, struct sip_msg* msg)
 	struct via_body *p = NULL;
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if(parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	RETURN0_res(p->comment);
 }
@@ -471,8 +478,9 @@ int select_via_params(str* res, select_t* s, struct sip_msg* msg)
 	struct via_param *q;
 
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type == SEL_PARAM_STR) {
+		if (parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	
 	for (q = p->param_lst;q;q=q->next) {
@@ -494,8 +502,9 @@ int select_via_params_spec(str* res, select_t* s, struct sip_msg* msg)
 	}
 	
 	// it's not neccessary to test if (s->n > 1)
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
+	if (s->params[1].type != SEL_PARAM_INT) {
+		if(parse_via_header(msg, 1, &p)<0) return -1;
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
 	if (!p) return -1;
 	
 	switch (s->params[s->n-1].v.i) {




More information about the sr-dev mailing list