Browse code

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

- reported by IƱaki Baz Castillo, fixes FS#138

Daniel-Constantin Mierla authored on 31/05/2012 12:44:19
Showing 2 changed files
... ...
@@ -223,6 +223,7 @@ int parse_select (char** p, select_t** s)
223 223
 		ERR("parse_select: no free memory\n");
224 224
 		return -1;
225 225
 	}
226
+	memset(sel, 0, sizeof(select_t));
226 227
 	if (w_parse_select(p, sel)<0) {
227 228
 		pkg_free(sel);
228 229
 		return -2;
... ...
@@ -336,8 +336,9 @@ int select_via(str* res, select_t* s, struct sip_msg* msg)
336 336
 {
337 337
 	struct via_body *p = NULL;
338 338
 	
339
-	if (((s->n == 1) || (s->params[1].type == SEL_PARAM_STR)) && (parse_via_header(msg, 1, &p)<0)) return -1;
340
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
339
+	if ((s->n == 1) || (s->params[1].type == SEL_PARAM_STR)) {
340
+		if (parse_via_header(msg, 1, &p)<0) return -1;
341
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
341 342
 	if (!p) return -1;
342 343
 	res->s=p->name.s;
343 344
 	res->len=p->bsize;
... ...
@@ -350,8 +351,9 @@ int select_via_name(str* res, select_t* s, struct sip_msg* msg)
350 350
 	struct via_body *p = NULL;
351 351
 	
352 352
 	// it's not neccessary to test if (s->n > 1)
353
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
354
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
353
+	if (s->params[1].type == SEL_PARAM_STR) {
354
+		if(parse_via_header(msg, 1, &p)<0) return -1;
355
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
355 356
 	if (!p) return -1;
356 357
 	RETURN0_res(p->name);
357 358
 }
... ...
@@ -361,8 +363,9 @@ int select_via_version(str* res, select_t* s, struct sip_msg* msg)
361 361
 	struct via_body *p = NULL;
362 362
 	
363 363
 	// it's not neccessary to test if (s->n > 1)
364
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
365
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
364
+	if (s->params[1].type == SEL_PARAM_STR) {
365
+		if (parse_via_header(msg, 1, &p)<0) return -1;
366
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
366 367
 	if (!p) return -1;
367 368
 	RETURN0_res(p->version);
368 369
 }
... ...
@@ -372,8 +375,9 @@ int select_via_transport(str* res, select_t* s, struct sip_msg* msg)
372 372
 	struct via_body *p = NULL;
373 373
 	
374 374
 	// it's not neccessary to test if (s->n > 1)
375
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
376
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
375
+	if (s->params[1].type == SEL_PARAM_STR) {
376
+		if(parse_via_header(msg, 1, &p)<0) return -1;
377
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
377 378
 	if (!p) return -1;
378 379
 	RETURN0_res(p->transport);
379 380
 }
... ...
@@ -383,8 +387,9 @@ int select_via_host(str* res, select_t* s, struct sip_msg* msg)
383 383
 	struct via_body *p = NULL;
384 384
 	
385 385
 	// it's not neccessary to test if (s->n > 1)
386
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
387
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
386
+	if (s->params[1].type == SEL_PARAM_STR) {
387
+		if (parse_via_header(msg, 1, &p)<0) return -1;
388
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
388 389
 	if (!p) return -1;
389 390
 	RETURN0_res(p->host);
390 391
 }
... ...
@@ -394,8 +399,9 @@ int select_via_port(str* res, select_t* s, struct sip_msg* msg)
394 394
 	struct via_body *p = NULL;
395 395
 	
396 396
 	// it's not neccessary to test if (s->n > 1)
397
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
398
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
397
+	if (s->params[1].type == SEL_PARAM_STR) {
398
+		if (parse_via_header(msg, 1, &p)<0) return -1;
399
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
399 400
 	if (!p) return -1;
400 401
 	RETURN0_res(p->port_str);
401 402
 }
... ...
@@ -405,8 +411,9 @@ int select_via_comment(str* res, select_t* s, struct sip_msg* msg)
405 405
 	struct via_body *p = NULL;
406 406
 	
407 407
 	// it's not neccessary to test if (s->n > 1)
408
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
409
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
408
+	if (s->params[1].type == SEL_PARAM_STR) {
409
+		if(parse_via_header(msg, 1, &p)<0) return -1;
410
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
410 411
 	if (!p) return -1;
411 412
 	RETURN0_res(p->comment);
412 413
 }
... ...
@@ -417,8 +424,9 @@ int select_via_params(str* res, select_t* s, struct sip_msg* msg)
417 417
 	struct via_param *q;
418 418
 
419 419
 	// it's not neccessary to test if (s->n > 1)
420
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
421
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
420
+	if (s->params[1].type == SEL_PARAM_STR) {
421
+		if (parse_via_header(msg, 1, &p)<0) return -1;
422
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
422 423
 	if (!p) return -1;
423 424
 	
424 425
 	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)
440 440
 	}
441 441
 	
442 442
 	// it's not neccessary to test if (s->n > 1)
443
-	if ((s->params[1].type == SEL_PARAM_STR) && (parse_via_header(msg, 1, &p)<0)) return -1;
444
-	else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
443
+	if (s->params[1].type != SEL_PARAM_INT) {
444
+		if(parse_via_header(msg, 1, &p)<0) return -1;
445
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
445 446
 	if (!p) return -1;
446 447
 	
447 448
 	switch (s->params[s->n-1].v.i) {