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 351
 	struct via_body *p = NULL;
351 352
 	
352 353
 	// 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;
354
+	if (s->params[1].type == SEL_PARAM_STR) {
355
+		if(parse_via_header(msg, 1, &p)<0) return -1;
356
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
355 357
 	if (!p) return -1;
356 358
 	RETURN0_res(p->name);
357 359
 }
... ...
@@ -361,8 +363,9 @@ int select_via_version(str* res, select_t* s, struct sip_msg* msg)
361 363
 	struct via_body *p = NULL;
362 364
 	
363 365
 	// 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;
366
+	if (s->params[1].type == SEL_PARAM_STR) {
367
+		if (parse_via_header(msg, 1, &p)<0) return -1;
368
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
366 369
 	if (!p) return -1;
367 370
 	RETURN0_res(p->version);
368 371
 }
... ...
@@ -372,8 +375,9 @@ int select_via_transport(str* res, select_t* s, struct sip_msg* msg)
372 375
 	struct via_body *p = NULL;
373 376
 	
374 377
 	// 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;
378
+	if (s->params[1].type == SEL_PARAM_STR) {
379
+		if(parse_via_header(msg, 1, &p)<0) return -1;
380
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
377 381
 	if (!p) return -1;
378 382
 	RETURN0_res(p->transport);
379 383
 }
... ...
@@ -383,8 +387,9 @@ int select_via_host(str* res, select_t* s, struct sip_msg* msg)
383 387
 	struct via_body *p = NULL;
384 388
 	
385 389
 	// 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;
390
+	if (s->params[1].type == SEL_PARAM_STR) {
391
+		if (parse_via_header(msg, 1, &p)<0) return -1;
392
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
388 393
 	if (!p) return -1;
389 394
 	RETURN0_res(p->host);
390 395
 }
... ...
@@ -394,8 +399,9 @@ int select_via_port(str* res, select_t* s, struct sip_msg* msg)
394 399
 	struct via_body *p = NULL;
395 400
 	
396 401
 	// 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;
402
+	if (s->params[1].type == SEL_PARAM_STR) {
403
+		if (parse_via_header(msg, 1, &p)<0) return -1;
404
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
399 405
 	if (!p) return -1;
400 406
 	RETURN0_res(p->port_str);
401 407
 }
... ...
@@ -405,8 +411,9 @@ int select_via_comment(str* res, select_t* s, struct sip_msg* msg)
405 411
 	struct via_body *p = NULL;
406 412
 	
407 413
 	// 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;
414
+	if (s->params[1].type == SEL_PARAM_STR) {
415
+		if(parse_via_header(msg, 1, &p)<0) return -1;
416
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
410 417
 	if (!p) return -1;
411 418
 	RETURN0_res(p->comment);
412 419
 }
... ...
@@ -417,8 +424,9 @@ int select_via_params(str* res, select_t* s, struct sip_msg* msg)
417 424
 	struct via_param *q;
418 425
 
419 426
 	// 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;
427
+	if (s->params[1].type == SEL_PARAM_STR) {
428
+		if (parse_via_header(msg, 1, &p)<0) return -1;
429
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
422 430
 	if (!p) return -1;
423 431
 	
424 432
 	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 448
 	}
441 449
 	
442 450
 	// 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;
451
+	if (s->params[1].type != SEL_PARAM_INT) {
452
+		if(parse_via_header(msg, 1, &p)<0) return -1;
453
+	} else if (parse_via_header(msg, s->params[1].v.i, &p)<0) return -1;
445 454
 	if (!p) return -1;
446 455
 	
447 456
 	switch (s->params[s->n-1].v.i) {