Browse code

tsilo: reworked checking ruri and contact parameters

- removed module name from log messages

Daniel-Constantin Mierla authored on 02/12/2021 15:12:01
Showing 1 changed files
... ...
@@ -407,7 +407,8 @@ static int ki_ts_append_to_uri(sip_msg_t* _msg, int tindex, int tlabel,
407 407
 /**
408 408
  *
409 409
  */
410
-static int w_ts_append_by_contact2(struct sip_msg* _msg, char *_table, char *_ruri) {
410
+static int w_ts_append_by_contact2(struct sip_msg* _msg, char *_table, char *_ruri)
411
+{
411 412
 	str ruri = STR_NULL;
412 413
 	str ruri_fixed = STR_NULL;
413 414
 
... ...
@@ -417,14 +418,19 @@ static int w_ts_append_by_contact2(struct sip_msg* _msg, char *_table, char *_ru
417 418
 
418 419
 	int rc;
419 420
 
421
+	if (_ruri==NULL) {
422
+		LM_ERR("invalid ruri parameter\n");
423
+		return -1;
424
+	}
425
+
420 426
 	/* parse R-URI */
421 427
 	if (fixup_get_svalue(_msg, (gparam_t*)_ruri, &ruri_fixed)!=0) {
422 428
 		LM_ERR("failed to convert r-uri parameter\n");
423 429
 		return -1;
424 430
 	}
425 431
 
426
-	if (_ruri==NULL || strlen(_ruri) <= 0 || ruri_fixed.len <= 0) {
427
-		LM_ERR("tsilo: invalid ruri parameter (empty or zero length).\n");
432
+	if (ruri_fixed.s == NULL || ruri_fixed.len <= 0) {
433
+		LM_ERR("invalid ruri parameter - empty or negative length\n");
428 434
 		return -1;
429 435
 	}
430 436
 
... ...
@@ -434,19 +440,19 @@ static int w_ts_append_by_contact2(struct sip_msg* _msg, char *_table, char *_ru
434 440
 	}
435 441
 
436 442
 	if (ts_check_uri(&ruri) < 0) {
437
-		LM_ERR("tsilo: failed to parse R-URI.\n");
443
+		LM_ERR("failed to parse R-URI.\n");
438 444
 		return -1;
439 445
 	}
440 446
 
441 447
 	/* parse Contact header */
442 448
 	if ((!_msg->contact && parse_headers(_msg, HDR_CONTACT_F, 0) != 0)
443 449
 			|| !_msg->contact) {
444
-		LM_WARN("tsilo: missing contact header or the value is empty/malformed.\n");
450
+		LM_WARN("missing contact header or the value is empty/malformed.\n");
445 451
 		return -1;
446 452
 	}
447 453
 	if (_msg->contact) {
448 454
 		if (parse_contact(_msg->contact) < 0) {
449
-			LM_WARN("tsilo: failed to parse Contact header.\n");
455
+			LM_WARN("failed to parse Contact header.\n");
450 456
 			return -1;
451 457
 		}
452 458
 		if (parse_uri(
... ...
@@ -454,7 +460,7 @@ static int w_ts_append_by_contact2(struct sip_msg* _msg, char *_table, char *_ru
454 460
 						((struct contact_body*)_msg->contact->parsed)->contacts->uri.len,
455 461
 						&curi) != 0 ) {
456 462
 			if (ts_check_uri(&_msg->contact->body) < 0) {	/* one more attempt */
457
-				LM_WARN("tsilo: failed to parse Contact header.\n");
463
+				LM_WARN("failed to parse Contact header.\n");
458 464
 				return -1;
459 465
 			}
460 466
 		}
... ...
@@ -470,7 +476,7 @@ static int w_ts_append_by_contact2(struct sip_msg* _msg, char *_table, char *_ru
470 476
 
471 477
 		if (pkg_str_dup(&contact, &tmp_contact) < 0) {
472 478
 			if (pkg_str_dup(&contact, &_msg->contact->body) < 0) { /* one more attempt */
473
-				LM_ERR("tsilo: problems when calling ts_append_contact(), cannot copy Contact parameter.\n");
479
+				LM_ERR("problems when calling ts_append_contact(), cannot copy Contact parameter.\n");
474 480
 				return -1;
475 481
 			}
476 482
 		}
... ...
@@ -490,7 +496,8 @@ static int w_ts_append_by_contact2(struct sip_msg* _msg, char *_table, char *_ru
490 496
 /**
491 497
  *
492 498
  */
493
-static int ki_ts_append_by_contact(sip_msg_t* _msg, str *_table, str *_ruri) {
499
+static int ki_ts_append_by_contact(sip_msg_t* _msg, str *_table, str *_ruri)
500
+{
494 501
 	str ruri = STR_NULL;
495 502
 	str contact = STR_NULL;
496 503
 	str tmp_contact = STR_NULL;
... ...
@@ -546,7 +553,9 @@ static int ki_ts_append_by_contact(sip_msg_t* _msg, str *_table, str *_ruri) {
546 553
 /**
547 554
  *
548 555
  */
549
-static int w_ts_append_by_contact3(struct sip_msg* _msg, char *_table, char *_ruri, char *_contact) {
556
+static int w_ts_append_by_contact3(struct sip_msg* _msg, char *_table,
557
+		char *_ruri, char *_contact)
558
+{
550 559
 	str ruri = STR_NULL;
551 560
 	str ruri_fixed = STR_NULL;
552 561
 
... ...
@@ -555,14 +564,18 @@ static int w_ts_append_by_contact3(struct sip_msg* _msg, char *_table, char *_ru
555 564
 
556 565
 	int rc;
557 566
 
567
+	if (_ruri==NULL || _contact==NULL) {
568
+		LM_ERR("invalid ruri or contact parameters\n");
569
+		return -1;
570
+	}
558 571
 	/* parse R-URI */
559 572
 	if (fixup_get_svalue(_msg, (gparam_t*)_ruri, &ruri_fixed)!=0) {
560 573
 		LM_ERR("failed to convert r-uri parameter\n");
561 574
 		return -1;
562 575
 	}
563 576
 
564
-	if (_ruri==NULL || strlen(_ruri) <= 0 || ruri_fixed.len <= 0) {
565
-		LM_ERR("tsilo: invalid ruri parameter.\n");
577
+	if (ruri_fixed.s == NULL || ruri_fixed.len <= 0) {
578
+		LM_ERR("invalid ruri parameter - empty or negative length\n");
566 579
 		return -1;
567 580
 	}
568 581
 
... ...
@@ -572,7 +585,7 @@ static int w_ts_append_by_contact3(struct sip_msg* _msg, char *_table, char *_ru
572 585
 	}
573 586
 
574 587
 	if (ts_check_uri(&ruri) < 0) {
575
-		LM_ERR("tsilo: failed to parse R-URI.\n");
588
+		LM_ERR("failed to parse R-URI.\n");
576 589
 		return -1;
577 590
 	}
578 591
 
... ...
@@ -582,8 +595,8 @@ static int w_ts_append_by_contact3(struct sip_msg* _msg, char *_table, char *_ru
582 595
 		return -1;
583 596
 	}
584 597
 
585
-	if (_contact==NULL || strlen(_contact) <= 0 || contact_fixed.len <= 0) {
586
-		LM_ERR("tsilo: invalid contact parameter.\n");
598
+	if (contact_fixed.s == NULL || contact_fixed.len <= 0) {
599
+		LM_ERR("invalid contact parameter value\n");
587 600
 		return -1;
588 601
 	}
589 602
 
... ...
@@ -593,7 +606,7 @@ static int w_ts_append_by_contact3(struct sip_msg* _msg, char *_table, char *_ru
593 606
 	}
594 607
 
595 608
 	if (ts_check_uri(&contact) < 0) {
596
-		LM_ERR("tsilo: failed to parse Contact parameter.\n");
609
+		LM_ERR("failed to parse Contact parameter.\n");
597 610
 		return -1;
598 611
 	}
599 612
 
... ...
@@ -609,7 +622,9 @@ static int w_ts_append_by_contact3(struct sip_msg* _msg, char *_table, char *_ru
609 622
 /**
610 623
  *
611 624
  */
612
-static int ki_ts_append_by_contact_uri(sip_msg_t* _msg, str *_table, str *_ruri, str *_contact) {
625
+static int ki_ts_append_by_contact_uri(sip_msg_t* _msg, str *_table, str *_ruri,
626
+		str *_contact)
627
+{
613 628
 	str ruri = STR_NULL;
614 629
 	str contact = STR_NULL;
615 630