Ver código fonte

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

- reported by Iñaki Baz Castillo, fixes FS#138
Daniel-Constantin Mierla 13 anos atrás
pai
commit
511841b7bc
2 arquivos alterados com 28 adições e 18 exclusões
  1. 1 0
      select.c
  2. 27 18
      select_core.c

+ 1 - 0
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;

+ 27 - 18
select_core.c

@@ -336,8 +336,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;
@@ -350,8 +351,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);
 }
@@ -361,8 +363,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);
 }
@@ -372,8 +375,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);
 }
@@ -383,8 +387,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);
 }
@@ -394,8 +399,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);
 }
@@ -405,8 +411,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);
 }
@@ -417,8 +424,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) {
@@ -440,8 +448,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) {