Browse code

core: check for non empty receive address and port in msg translator

Daniel-Constantin Mierla authored on 07/04/2021 09:33:24
Showing 1 changed files
... ...
@@ -597,7 +597,7 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
597 597
 #define SUBST_LUMP_LEN(subst_l) \
598 598
 		switch((subst_l)->u.subst){ \
599 599
 			case SUBST_RCV_IP: \
600
-				if (msg->rcv.bind_address){ \
600
+				if (msg->rcv.bind_address && STR_WITHVAL(recv_address_str)){ \
601 601
 					new_len+=recv_address_str->len; \
602 602
 					if (msg->rcv.bind_address->address.af!=AF_INET) \
603 603
 						new_len+=2; \
... ...
@@ -607,7 +607,7 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
607 607
 				}; \
608 608
 				break; \
609 609
 			case SUBST_RCV_PORT: \
610
-				if (msg->rcv.bind_address){ \
610
+				if (msg->rcv.bind_address && STR_WITHVAL(recv_port_str)){ \
611 611
 					new_len+=recv_port_str->len; \
612 612
 				}else{ \
613 613
 					/* FIXME */ \
... ...
@@ -646,14 +646,14 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
646 646
 				break; \
647 647
 			case SUBST_RCV_ALL: \
648 648
 			case SUBST_RCV_ALL_EX: \
649
-				if (msg->rcv.bind_address){ \
649
+				if (msg->rcv.bind_address && STR_WITHVAL(recv_address_str)){ \
650 650
 					new_len+=recv_address_str->len; \
651 651
 					if ((msg->rcv.bind_address->address.af==AF_INET6)\
652 652
 							&& (recv_address_str->s[0]!='[')\
653 653
 							&& (memchr(recv_address_str->s, ':',\
654 654
 								recv_address_str->len)!=NULL))\
655 655
 						new_len+=2; \
656
-					if (recv_port_no!=SIP_PORT){ \
656
+					if (recv_port_no!=SIP_PORT && STR_WITHVAL(recv_port_str)){ \
657 657
 						/* add :port_no */ \
658 658
 						new_len+=1+recv_port_str->len; \
659 659
 					}\
... ...
@@ -990,7 +990,7 @@ void process_lumps( struct sip_msg* msg,
990 990
 #define SUBST_LUMP(subst_l) \
991 991
 	switch((subst_l)->u.subst){ \
992 992
 		case SUBST_RCV_IP: \
993
-			if (msg->rcv.bind_address){  \
993
+			if (msg->rcv.bind_address && STR_WITHVAL(recv_address_str)){  \
994 994
 				if (msg->rcv.bind_address->address.af!=AF_INET){\
995 995
 					new_buf[offset]='['; offset++; \
996 996
 				}\
... ...
@@ -1006,7 +1006,7 @@ void process_lumps( struct sip_msg* msg,
1006 1006
 			}; \
1007 1007
 			break; \
1008 1008
 		case SUBST_RCV_PORT: \
1009
-			if (msg->rcv.bind_address){  \
1009
+			if (msg->rcv.bind_address && STR_WITHVAL(recv_port_str)){  \
1010 1010
 				memcpy(new_buf+offset, recv_port_str->s, \
1011 1011
 						recv_port_str->len); \
1012 1012
 				offset+=recv_port_str->len; \
... ...
@@ -1017,7 +1017,7 @@ void process_lumps( struct sip_msg* msg,
1017 1017
 			break; \
1018 1018
 		case SUBST_RCV_ALL: \
1019 1019
 		case SUBST_RCV_ALL_EX: \
1020
-			if (msg->rcv.bind_address){  \
1020
+			if (msg->rcv.bind_address && STR_WITHVAL(recv_address_str)){  \
1021 1021
 				/* address */ \
1022 1022
 				if ((msg->rcv.bind_address->address.af==AF_INET6)\
1023 1023
 						&& (recv_address_str->s[0]!='[')\
... ...
@@ -1035,7 +1035,7 @@ void process_lumps( struct sip_msg* msg,
1035 1035
 					new_buf[offset]=']'; offset++; \
1036 1036
 				}\
1037 1037
 				/* :port */ \
1038
-				if (recv_port_no!=SIP_PORT){ \
1038
+				if (recv_port_no!=SIP_PORT && STR_WITHVAL(recv_port_str)){ \
1039 1039
 					new_buf[offset]=':'; offset++; \
1040 1040
 					memcpy(new_buf+offset, \
1041 1041
 							recv_port_str->s, \
Browse code

core: use same condition for extra_params in create_via_hf()

Daniel-Constantin Mierla authored on 07/04/2021 07:53:39
Showing 1 changed files
... ...
@@ -2992,12 +2992,14 @@ char* create_via_hf(unsigned int *len,
2992 2992
 		/* params so far + ';rport' + '\0' */
2993 2993
 		via = (char*)pkg_malloc(extra_params.len+RPORT_LEN);
2994 2994
 		if(via==0) {
2995
-		        PKG_MEM_ERROR;
2995
+			PKG_MEM_ERROR;
2996 2996
 			if (extra_params.s) pkg_free(extra_params.s);
2997 2997
 			return 0;
2998 2998
 		}
2999
-		if(extra_params.len!=0) {
2999
+		if(extra_params.s!=NULL && extra_params.len>0) {
3000 3000
 			memcpy(via, extra_params.s, extra_params.len);
3001
+		}
3002
+		if(extra_params.s!=NULL) {
3001 3003
 			pkg_free(extra_params.s);
3002 3004
 		}
3003 3005
 		memcpy(via + extra_params.len, RPORT, RPORT_LEN-1);
... ...
@@ -3018,8 +3020,10 @@ char* create_via_hf(unsigned int *len,
3018 3020
 				if (extra_params.s) pkg_free(extra_params.s);
3019 3021
 				return 0;
3020 3022
 			}
3021
-			if(extra_params.len != 0) {
3023
+			if(extra_params.s!=NULL && extra_params.len>0) {
3022 3024
 				memcpy(via, extra_params.s, extra_params.len);
3025
+			}
3026
+			if(extra_params.s!=NULL) {
3023 3027
 				pkg_free(extra_params.s);
3024 3028
 			}
3025 3029
 			memcpy(via + extra_params.len, sbuf, slen);
... ...
@@ -3038,12 +3042,14 @@ char* create_via_hf(unsigned int *len,
3038 3042
 		if(xparams.len>0) {
3039 3043
 			via = (char*)pkg_malloc(extra_params.len+xparams.len+2);
3040 3044
 			if(via==0) {
3041
-			        PKG_MEM_ERROR;
3045
+				PKG_MEM_ERROR;
3042 3046
 				if (extra_params.s) pkg_free(extra_params.s);
3043 3047
 				return 0;
3044 3048
 			}
3045
-			if(extra_params.len != 0) {
3049
+			if(extra_params.s!=NULL && extra_params.len>0) {
3046 3050
 				memcpy(via, extra_params.s, extra_params.len);
3051
+			}
3052
+			if(extra_params.s!=NULL) {
3047 3053
 				pkg_free(extra_params.s);
3048 3054
 			}
3049 3055
 			/* add ';' between via parameters */
Browse code

core: new option BUILD_NEW_LOCAL_VIA to recreate the local via

- to be used from tm uac when a local-generated request has to update
the via header following the event route execution

Daniel-Constantin Mierla authored on 17/02/2021 07:21:36
Showing 1 changed files
... ...
@@ -1971,7 +1971,7 @@ clean:
1971 1971
   * depending on the presence of the BUILD_IN_SHM flag, needs freeing when
1972 1972
   *   done) and sets returned_len or 0 on error.
1973 1973
   */
1974
-char * build_req_buf_from_sip_req( struct sip_msg* msg,
1974
+char * build_req_buf_from_sip_req(struct sip_msg* msg,
1975 1975
 								unsigned int *returned_len,
1976 1976
 								struct dest_info* send_info,
1977 1977
 								unsigned int mode)
... ...
@@ -1987,6 +1987,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1987 1987
 	unsigned int offset, s_offset, size;
1988 1988
 	struct lump* via_anchor;
1989 1989
 	struct lump* via_lump;
1990
+	struct lump* via_rm;
1990 1991
 	struct lump* via_insert_param;
1991 1992
 	struct lump* path_anchor;
1992 1993
 	struct lump* path_lump;
... ...
@@ -2032,11 +2033,22 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
2032 2033
 
2033 2034
 	via_anchor=anchor_lump(msg, msg->via1->hdr.s-buf, 0, HDR_VIA_T);
2034 2035
 	if (unlikely(via_anchor==0)) goto error00;
2035
-	line_buf = create_via_hf( &via_len, msg, send_info, &branch);
2036
+	line_buf = create_via_hf(&via_len, msg, send_info, &branch);
2036 2037
 	if (unlikely(!line_buf)){
2037 2038
 		LM_ERR("could not create Via header\n");
2038 2039
 		goto error00;
2039 2040
 	}
2041
+	if(unlikely(mode&BUILD_NEW_LOCAL_VIA)) {
2042
+		/* delete exiting top Via header */
2043
+		via_rm = del_lump(msg, msg->h_via1->name.s - msg->buf,
2044
+				msg->h_via1->len, 0);
2045
+		if (via_rm==0) {
2046
+			LM_ERR("failed to remove exiting Via header\n");
2047
+			goto error00;
2048
+		}
2049
+		/* do not update old Via header anymore */
2050
+		mode |= BUILD_NO_VIA1_UPDATE;
2051
+	}
2040 2052
 after_local_via:
2041 2053
 	if(unlikely(mode&BUILD_NO_VIA1_UPDATE))
2042 2054
 		goto after_update_via1;
Browse code

core: check if the tcp clone rcv buffer is set when applying changes

Daniel-Constantin Mierla authored on 26/11/2020 12:54:42
Showing 1 changed files
... ...
@@ -3252,7 +3252,12 @@ int sip_msg_update_buffer(sip_msg_t *msg, str *obuf)
3252 3252
 		LM_ERR("invalid buffer parameter\n");
3253 3253
 		return -1;
3254 3254
 	}
3255
-
3255
+#ifdef USE_TCP
3256
+	if(tcp_get_clone_rcvbuf()==0) {
3257
+		LM_ERR("tcp clone received buffer not enabled\n");
3258
+		return -1;
3259
+	}
3260
+#endif
3256 3261
 	if(obuf->len >= BUF_SIZE) {
3257 3262
 		LM_ERR("new buffer is too large (%d)\n", obuf->len);
3258 3263
 		return -1;
Browse code

core: added local_rport global parameter

- similar to add_local_rport() but set globally

Daniel-Constantin Mierla authored on 11/11/2020 08:29:08
Showing 1 changed files
... ...
@@ -114,6 +114,7 @@ extern int version_len;
114 114
 
115 115
 str _ksr_xavp_via_params = STR_NULL;
116 116
 str _ksr_xavp_via_fields = STR_NULL;
117
+int ksr_local_rport = 0;
117 118
 
118 119
 /** per process fixup function for global_req_flags.
119 120
   * It should be called from the configuration framework.
... ...
@@ -2975,7 +2976,7 @@ char* create_via_hf(unsigned int *len,
2975 2976
 #endif /* USE_TCP || USE_SCTP */
2976 2977
 
2977 2978
 	/* test and add rport parameter to local via - rfc3581 */
2978
-	if(msg && msg->msg_flags&FL_ADD_LOCAL_RPORT) {
2979
+	if((ksr_local_rport) || (msg && (msg->msg_flags&FL_ADD_LOCAL_RPORT))) {
2979 2980
 		/* params so far + ';rport' + '\0' */
2980 2981
 		via = (char*)pkg_malloc(extra_params.len+RPORT_LEN);
2981 2982
 		if(via==0) {
Browse code

core: added missing field in sip_msg_update_buffer

- added a missing field in sip_msg_update_buffer()
when restoring message fiedls: msg->pid.

Aleksandar Yosifov authored on 09/11/2020 12:37:26
Showing 1 changed files
... ...
@@ -3276,6 +3276,7 @@ int sip_msg_update_buffer(sip_msg_t *msg, str *obuf)
3276 3276
 	/* restore msg fields */
3277 3277
 	msg->buf = tmp.buf;
3278 3278
 	msg->id = tmp.id;
3279
+	msg->pid = tmp.pid;
3279 3280
 	msg->rcv = tmp.rcv;
3280 3281
 	msg->set_global_address = tmp.set_global_address;
3281 3282
 	msg->set_global_port = tmp.set_global_port;
Browse code

core: new conditional lump types SUBST_RCV_ALL_EX and SUBST_SND_ALL_EX

- build conditional uri adding socket name in 'sn' param

Daniel-Constantin Mierla authored on 02/04/2020 11:29:56
Showing 1 changed files
... ...
@@ -592,7 +592,7 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
592 592
 	#define RCVCOMP_LUMP_LEN
593 593
 	#define SENDCOMP_LUMP_LEN
594 594
 #endif /*USE_COMP */
595
-	
595
+
596 596
 #define SUBST_LUMP_LEN(subst_l) \
597 597
 		switch((subst_l)->u.subst){ \
598 598
 			case SUBST_RCV_IP: \
... ...
@@ -644,6 +644,7 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
644 644
 				}; \
645 645
 				break; \
646 646
 			case SUBST_RCV_ALL: \
647
+			case SUBST_RCV_ALL_EX: \
647 648
 				if (msg->rcv.bind_address){ \
648 649
 					new_len+=recv_address_str->len; \
649 650
 					if ((msg->rcv.bind_address->address.af==AF_INET6)\
... ...
@@ -679,6 +680,11 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
679 680
 						LM_CRIT("unknown proto %d\n", \
680 681
 								msg->rcv.bind_address->proto); \
681 682
 					}\
683
+					if((subst_l)->u.subst==SUBST_RCV_ALL_EX \
684
+								&& msg->rcv.bind_address->sockname.len>0) { \
685
+						new_len+=SOCKNAME_PARAM_LEN \
686
+								+ msg->rcv.bind_address->sockname.len; \
687
+					} \
682 688
 					RCVCOMP_LUMP_LEN \
683 689
 				}else{ \
684 690
 					/* FIXME */ \
... ...
@@ -732,6 +738,7 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
732 738
 				}; \
733 739
 				break; \
734 740
 			case SUBST_SND_ALL: \
741
+			case SUBST_SND_ALL_EX: \
735 742
 				if (send_sock){ \
736 743
 					new_len+=send_address_str->len; \
737 744
 					if ((send_sock->address.af==AF_INET6) && \
... ...
@@ -767,6 +774,11 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
767 774
 						default: \
768 775
 						LM_CRIT("unknown proto %d\n", send_sock->proto); \
769 776
 					}\
777
+					if((subst_l)->u.subst==SUBST_SND_ALL_EX \
778
+								&& send_sock->sockname.len>0) { \
779
+						new_len+=SOCKNAME_PARAM_LEN \
780
+								+ send_sock->sockname.len; \
781
+					} \
770 782
 					SENDCOMP_LUMP_LEN \
771 783
 				}else{ \
772 784
 					/* FIXME */ \
... ...
@@ -1003,6 +1015,7 @@ void process_lumps( struct sip_msg* msg,
1003 1015
 			}; \
1004 1016
 			break; \
1005 1017
 		case SUBST_RCV_ALL: \
1018
+		case SUBST_RCV_ALL_EX: \
1006 1019
 			if (msg->rcv.bind_address){  \
1007 1020
 				/* address */ \
1008 1021
 				if ((msg->rcv.bind_address->address.af==AF_INET6)\
... ...
@@ -1066,6 +1079,15 @@ void process_lumps( struct sip_msg* msg,
1066 1079
 					default: \
1067 1080
 						LM_CRIT("unknown proto %d\n", msg->rcv.bind_address->proto); \
1068 1081
 				} \
1082
+				if((subst_l)->u.subst==SUBST_RCV_ALL_EX \
1083
+								&& msg->rcv.bind_address->sockname.len>0) { \
1084
+					memcpy(new_buf+offset, SOCKNAME_PARAM, \
1085
+								SOCKNAME_PARAM_LEN); \
1086
+					offset+=SOCKNAME_PARAM_LEN; \
1087
+					memcpy(new_buf+offset, msg->rcv.bind_address->sockname.s, \
1088
+							msg->rcv.bind_address->sockname.len); \
1089
+					offset+=msg->rcv.bind_address->sockname.len; \
1090
+				} \
1069 1091
 				RCVCOMP_PARAM_ADD \
1070 1092
 			}else{  \
1071 1093
 				/*FIXME*/ \
... ...
@@ -1101,6 +1123,7 @@ void process_lumps( struct sip_msg* msg,
1101 1123
 			}; \
1102 1124
 			break; \
1103 1125
 		case SUBST_SND_ALL: \
1126
+		case SUBST_SND_ALL_EX: \
1104 1127
 			if (send_sock){  \
1105 1128
 				/* address */ \
1106 1129
 				if ((send_sock->address.af==AF_INET6)\
... ...
@@ -1164,6 +1187,15 @@ void process_lumps( struct sip_msg* msg,
1164 1187
 					default: \
1165 1188
 						LM_CRIT("unknown proto %d\n", send_sock->proto); \
1166 1189
 				} \
1190
+				if((subst_l)->u.subst==SUBST_SND_ALL_EX \
1191
+							&& send_sock->sockname.len>0) { \
1192
+					memcpy(new_buf+offset, SOCKNAME_PARAM, \
1193
+							SOCKNAME_PARAM_LEN); \
1194
+					offset+=SOCKNAME_PARAM_LEN; \
1195
+					memcpy(new_buf+offset, send_sock->sockname.s, \
1196
+							send_sock->sockname.len); \
1197
+					offset+=send_sock->sockname.len; \
1198
+				} \
1167 1199
 				SENDCOMP_PARAM_ADD \
1168 1200
 			}else{  \
1169 1201
 				/*FIXME*/ \
Browse code

core: propagate xflags inside sip_msg_update_buffer() to new msg

- xflags were lost when the msg structure was reinitialized (e.g., after
msg_apply_chages())

Daniel-Constantin Mierla authored on 21/02/2020 07:39:47
Showing 1 changed files
... ...
@@ -3249,6 +3249,7 @@ int sip_msg_update_buffer(sip_msg_t *msg, str *obuf)
3249 3249
 	msg->set_global_port = tmp.set_global_port;
3250 3250
 	msg->flags = tmp.flags;
3251 3251
 	msg->msg_flags = tmp.msg_flags;
3252
+	memcpy(msg->xflags, tmp.xflags, KSR_XFLAGS_SIZE * sizeof(flag_t));
3252 3253
 	msg->hash_index = tmp.hash_index;
3253 3254
 	msg->force_send_socket = tmp.force_send_socket;
3254 3255
 	msg->fwd_send_flags = tmp.fwd_send_flags;
Browse code

core: msg translator - warning log made info for multipart body processing

- check boundary cannot find boundary value in content-type when the request
is turned into multipart body
- use different return code for this case
- a few realignmets for curly braces to be corherent across the
respective functions

Daniel-Constantin Mierla authored on 24/01/2020 09:20:09
Showing 1 changed files
... ...
@@ -1710,16 +1710,14 @@ int get_boundary(struct sip_msg* msg, str* boundary)
1710 1710
 
1711 1711
 	params.s = memchr(msg->content_type->body.s, ';',
1712 1712
 		msg->content_type->body.len);
1713
-	if (params.s == NULL)
1714
-	{
1713
+	if (params.s == NULL) {
1715 1714
 		LM_INFO("Content-Type hdr has no boundary params <%.*s>\n",
1716 1715
 				msg->content_type->body.len, msg->content_type->body.s);
1717
-		return -1;
1716
+		return -2;
1718 1717
 	}
1719 1718
 	params.len = msg->content_type->body.len -
1720 1719
 		(params.s - msg->content_type->body.s);
1721
-	if (parse_params(&params, CLASS_ANY, &hooks, &list) < 0)
1722
-	{
1720
+	if (parse_params(&params, CLASS_ANY, &hooks, &list) < 0) {
1723 1721
 		LM_ERR("while parsing Content-Type params\n");
1724 1722
 		return -1;
1725 1723
 	}
... ...
@@ -1727,11 +1725,9 @@ int get_boundary(struct sip_msg* msg, str* boundary)
1727 1725
 	boundary->len = 0;
1728 1726
 	for (p = list; p; p = p->next) {
1729 1727
 		if ((p->name.len == 8)
1730
-			&& (strncasecmp(p->name.s, "boundary", 8) == 0))
1731
-		{
1728
+			&& (strncasecmp(p->name.s, "boundary", 8) == 0)) {
1732 1729
 			boundary->s = pkg_malloc(p->body.len + 2);
1733
-			if (boundary->s == NULL)
1734
-			{
1730
+			if (boundary->s == NULL) {
1735 1731
 				free_params(list);
1736 1732
 				PKG_MEM_ERROR;
1737 1733
 				return -1;
... ...
@@ -1764,9 +1760,17 @@ int check_boundaries(struct sip_msg *msg, struct dest_info *send_info)
1764 1760
 	int t, ret, lb_size;
1765 1761
 	char *pb;
1766 1762
 
1767
-	if(!(msg->msg_flags&FL_BODY_MULTIPART)) return 0;
1768
-	else
1769
-	{
1763
+	if(!(msg->msg_flags&FL_BODY_MULTIPART)) {
1764
+		LM_DBG("no multi-part body\n");
1765
+		return 0;
1766
+	} else {
1767
+		if((t = get_boundary(msg, &ob)) != 0) {
1768
+			if(t==-2) {
1769
+				LM_INFO("no boundary - maybe just turning into multipart body\n");
1770
+				return -2;
1771
+			}
1772
+			return -1;
1773
+		}
1770 1774
 		buf.s = build_body(msg, (unsigned int *)&buf.len, &ret, send_info);
1771 1775
 		if(ret) {
1772 1776
 			LM_ERR("Can't get body\n");
... ...
@@ -1774,10 +1778,6 @@ int check_boundaries(struct sip_msg *msg, struct dest_info *send_info)
1774 1778
 		}
1775 1779
 		tmp.s = buf.s;
1776 1780
 		t = tmp.len = buf.len;
1777
-		if(get_boundary(msg, &ob)!=0) {
1778
-			if(tmp.s) pkg_free(tmp.s);
1779
-			return -1;
1780
-		}
1781 1781
 		if(str_append(&ob, &bsuffix, &b)!=0) {
1782 1782
 			LM_ERR("Can't append suffix to boundary\n");
1783 1783
 			goto error;
... ...
@@ -1961,6 +1961,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1961 1961
 	unsigned int flags;
1962 1962
 	unsigned int udp_mtu;
1963 1963
 	struct dest_info di;
1964
+	int ret;
1964 1965
 
1965 1966
 	via_insert_param=0;
1966 1967
 	uri_len=0;
... ...
@@ -1978,9 +1979,10 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1978 1979
 	path_buf.len=0;
1979 1980
 
1980 1981
 	flags=msg->msg_flags|global_req_flags;
1981
-	if(check_boundaries(msg, send_info)<0){
1982
-		LM_WARN("check_boundaries error\n");
1982
+	if((ret = check_boundaries(msg, send_info)) < 0){
1983
+		LM_INFO("check boundaries negative (%d)\n", ret);
1983 1984
 	}
1985
+
1984 1986
 	/* Calculate message body difference and adjust Content-Length */
1985 1987
 	body_delta = lumps_len(msg, msg->body_lumps, send_info);
1986 1988
 	if (adjust_clen(msg, body_delta, send_info->proto) < 0) {
Browse code

core: move existing MD5 hash implementation into new core subfolder crypto

Henning Westerholt authored on 02/10/2019 22:11:37
Showing 1 changed files
... ...
@@ -91,7 +91,6 @@
91 91
 #include "mem/mem.h"
92 92
 #include "dprint.h"
93 93
 #include "config.h"
94
-#include "md5utils.h"
95 94
 #include "data_lump.h"
96 95
 #include "data_lump_rpl.h"
97 96
 #include "ip_addr.h"
Browse code

core: restore alignment after replacing mem error logs

Daniel-Constantin Mierla authored on 12/08/2019 08:28:05
Showing 1 changed files
... ...
@@ -2187,10 +2187,11 @@ after_update_via1:
2187 2187
 		new_buf=(char*)pkg_malloc(new_len+1);
2188 2188
 	if (new_buf==0){
2189 2189
 		ser_error=E_OUT_OF_MEM;
2190
-		if(unlikely(mode&BUILD_IN_SHM))
2191
-                        SHM_MEM_ERROR;
2192
-                else
2193
-                        PKG_MEM_ERROR;
2190
+		if(unlikely(mode&BUILD_IN_SHM)) {
2191
+			SHM_MEM_ERROR;
2192
+		} else {
2193
+			PKG_MEM_ERROR;
2194
+		}
2194 2195
 		goto error00;
2195 2196
 	}
2196 2197
 
Browse code

core: set msg->pid when building local sip_msg_t from buf

Daniel-Constantin Mierla authored on 26/02/2019 06:57:12
Showing 1 changed files
... ...
@@ -3194,6 +3194,7 @@ int build_sip_msg_from_buf(struct sip_msg *msg, char *buf, int len,
3194 3194
 
3195 3195
 	memset(msg, 0, sizeof(sip_msg_t));
3196 3196
 	msg->id = id;
3197
+	msg->pid = my_pid();
3197 3198
 	msg->buf = buf;
3198 3199
 	msg->len = len;
3199 3200
 	if (parse_msg(buf, len, msg)!=0) {
Browse code

core: fix an error in check_via_address, reported from Mojtaba, mespio at gmail dot com

- fix an error in check_via_address, reported from Mojtaba, mespio at gmail dot com
- use the same logic for IPv4 string comparison as for IPv6
- the old comparison could return true for e.g. via="192.168.1.1", src="192.1.1.100"
- the new logic is also faster for the trivial case with different string length

Henning Westerholt authored on 30/12/2018 00:17:15
Showing 1 changed files
... ...
@@ -179,7 +179,7 @@ static int check_via_address(struct ip_addr* ip, str *name,
179 179
 				LM_CRIT("invalid Via host name\n");
180 180
 				return -1;
181 181
 			}
182
-			if (strncmp(name->s, s, name->len)==0)
182
+			if (len==name->len&&(strncmp(name->s, s, name->len)==0))
183 183
 				return 0;
184 184
 		}
185 185
 	}else{
Browse code

core: use generic PKG_MEM_ERROR, SHM_ERROR and _CRITICAL helper defines in core

- refactoring of the core to use generic PKG_MEM_ERROR, SHM_ERROR,
PKG_MEM_CRITICAL, SHM_MEM_CRITICAL and SYS_MEM_ERROR helper defines
- unify many different error messages in different spellings
- add a few missing error handler for allocation errors after (found
with a complete review of all memory allocation functions in core)
- no other functional changes, change has been reviewed two times

Henning Westerholt authored on 23/12/2018 21:31:03
Showing 1 changed files
... ...
@@ -332,7 +332,7 @@ char* received_builder(struct sip_msg *msg, unsigned int *received_len)
332 332
 	buf=pkg_malloc(sizeof(char)*MAX_RECEIVED_SIZE);
333 333
 	if (buf==0){
334 334
 		ser_error=E_OUT_OF_MEM;
335
-		LM_ERR("out of memory\n");
335
+		PKG_MEM_ERROR;
336 336
 		return 0;
337 337
 	}
338 338
 	memcpy(buf, RECEIVED, RECEIVED_LEN);
... ...
@@ -365,7 +365,7 @@ char* rport_builder(struct sip_msg *msg, unsigned int *rport_len)
365 365
 	buf=pkg_malloc(sizeof(char)*(len+1));/* space for null term */
366 366
 	if (buf==0){
367 367
 		ser_error=E_OUT_OF_MEM;
368
-		LM_ERR("out of memory\n");
368
+		PKG_MEM_ERROR;
369 369
 		return 0;
370 370
 	}
371 371
 	memcpy(buf, RPORT, RPORT_LEN);
... ...
@@ -397,7 +397,7 @@ char* id_builder(struct sip_msg* msg, unsigned int *id_len)
397 397
 	buf=pkg_malloc(sizeof(char)*(len+1));/* place for ending \0 */
398 398
 	if (buf==0){
399 399
 		ser_error=E_OUT_OF_MEM;
400
-		LM_ERR("out of memory\n");
400
+		PKG_MEM_ERROR;
401 401
 		return 0;
402 402
 	}
403 403
 	memcpy(buf, ID_PARAM, ID_PARAM_LEN);
... ...
@@ -440,7 +440,7 @@ char* clen_builder(	struct sip_msg* msg, int *clen_len, int diff,
440 440
 	buf=pkg_malloc(sizeof(char)*(len+1));
441 441
 	if (buf==0){
442 442
 		ser_error=E_OUT_OF_MEM;
443
-		LM_ERR("out of memory\n");
443
+		PKG_MEM_ERROR;
444 444
 		return 0;
445 445
 	}
446 446
 	if (body_only) {
... ...
@@ -1734,7 +1734,7 @@ int get_boundary(struct sip_msg* msg, str* boundary)
1734 1734
 			if (boundary->s == NULL)
1735 1735
 			{
1736 1736
 				free_params(list);
1737
-				LM_ERR("no memory for boundary string\n");
1737
+				PKG_MEM_ERROR;
1738 1738
 				return -1;
1739 1739
 			}
1740 1740
 			*(boundary->s) = '-';
... ...
@@ -2087,7 +2087,7 @@ after_update_via1:
2087 2087
 		path_buf.len=ROUTE_PREFIX_LEN+msg->path_vec.len+CRLF_LEN;
2088 2088
 		path_buf.s=pkg_malloc(path_buf.len+1);
2089 2089
 		if (unlikely(path_buf.s==0)){
2090
-			LM_ERR("out of memory\n");
2090
+		        PKG_MEM_ERROR;
2091 2091
 			ser_error=E_OUT_OF_MEM;
2092 2092
 			goto error00;
2093 2093
 		}
... ...
@@ -2187,7 +2187,10 @@ after_update_via1:
2187 2187
 		new_buf=(char*)pkg_malloc(new_len+1);
2188 2188
 	if (new_buf==0){
2189 2189
 		ser_error=E_OUT_OF_MEM;
2190
-		LM_ERR("out of memory\n");
2190
+		if(unlikely(mode&BUILD_IN_SHM))
2191
+                        SHM_MEM_ERROR;
2192
+                else
2193
+                        PKG_MEM_ERROR;
2191 2194
 		goto error00;
2192 2195
 	}
2193 2196
 
... ...
@@ -2289,7 +2292,7 @@ char * generate_res_buf_from_sip_res( struct sip_msg* msg,
2289 2292
 	new_buf=(char*)pkg_malloc(new_len+1); /* +1 is for debugging
2290 2293
 											 (\0 to print it )*/
2291 2294
 	if (new_buf==0){
2292
-		LM_ERR("out of mem\n");
2295
+	        PKG_MEM_ERROR;
2293 2296
 		goto error;
2294 2297
 	}
2295 2298
 	new_buf[new_len]=0; /* debug: print the message */
... ...
@@ -2446,7 +2449,7 @@ char * build_res_buf_from_sip_req( unsigned int code, str *text ,str *new_tag,
2446 2449
 	buf = (char*) pkg_malloc( len+1 );
2447 2450
 	if (!buf)
2448 2451
 	{
2449
-		LM_ERR("out of memory; needs %d\n",len);
2452
+	        PKG_MEM_ERROR;
2450 2453
 		goto error01;
2451 2454
 	}
2452 2455
 
... ...
@@ -2770,7 +2773,7 @@ char* via_builder(unsigned int *len, sip_msg_t *msg,
2770 2773
 	line_buf=pkg_malloc( max_len );
2771 2774
 	if (line_buf==0){
2772 2775
 		ser_error=E_OUT_OF_MEM;
2773
-		LM_ERR("out of memory\n");
2776
+		PKG_MEM_ERROR;
2774 2777
 		return 0;
2775 2778
 	}
2776 2779
 
... ...
@@ -2942,7 +2945,7 @@ char* create_via_hf(unsigned int *len,
2942 2945
 		/* params so far + ';rport' + '\0' */
2943 2946
 		via = (char*)pkg_malloc(extra_params.len+RPORT_LEN);
2944 2947
 		if(via==0) {
2945
-			LM_ERR("building local rport via param failed\n");
2948
+		        PKG_MEM_ERROR;
2946 2949
 			if (extra_params.s) pkg_free(extra_params.s);
2947 2950
 			return 0;
2948 2951
 		}
... ...
@@ -2964,7 +2967,7 @@ char* create_via_hf(unsigned int *len,
2964 2967
 		} else {
2965 2968
 			via = (char*)pkg_malloc(extra_params.len+slen+1);
2966 2969
 			if(via==0) {
2967
-				LM_ERR("building srvid param failed\n");
2970
+			        PKG_MEM_ERROR;
2968 2971
 				if (extra_params.s) pkg_free(extra_params.s);
2969 2972
 				return 0;
2970 2973
 			}
... ...
@@ -2988,7 +2991,7 @@ char* create_via_hf(unsigned int *len,
2988 2991
 		if(xparams.len>0) {
2989 2992
 			via = (char*)pkg_malloc(extra_params.len+xparams.len+2);
2990 2993
 			if(via==0) {
2991
-				LM_ERR("building xavps params failed\n");
2994
+			        PKG_MEM_ERROR;
2992 2995
 				if (extra_params.s) pkg_free(extra_params.s);
2993 2996
 				return 0;
2994 2997
 			}
... ...
@@ -3048,7 +3051,7 @@ char * build_only_headers( struct sip_msg* msg, int skip_first_line,
3048 3051
 
3049 3052
 	new_buf = (char *)pkg_malloc(new_len+1);
3050 3053
 	if (!new_buf) {
3051
-		LM_ERR("Not enough memory\n");
3054
+	        PKG_MEM_ERROR;
3052 3055
 		*error = -1;
3053 3056
 		return 0;
3054 3057
 	}
... ...
@@ -3098,7 +3101,7 @@ char * build_body( struct sip_msg* msg,
3098 3101
 
3099 3102
 	new_buf = (char *)pkg_malloc(new_len+1);
3100 3103
 	if (!new_buf) {
3101
-		LM_ERR("Not enough memory\n");
3104
+	        PKG_MEM_ERROR;
3102 3105
 		*error = -1;
3103 3106
 		return 0;
3104 3107
 	}
... ...
@@ -3158,7 +3161,7 @@ char * build_all( struct sip_msg* msg, int touch_clen,
3158 3161
 
3159 3162
 	new_buf = (char *)pkg_malloc(new_len+1);
3160 3163
 	if (!new_buf) {
3161
-		LM_ERR("Not enough memory\n");
3164
+	        PKG_MEM_ERROR;
3162 3165
 		*error = -1;
3163 3166
 		return 0;
3164 3167
 	}
Browse code

core: fixed segmentation fault when handling multipart bodies

Function check_boundaries() in msg_translator.c not handling property the length of the buffers when it needs to repair the boundary, getting a negative lenght and causing a segmentation fault.

Nacho Garcia Segovia authored on 07/12/2018 10:19:52 • Victor Seva committed on 07/12/2018 10:54:06
Showing 1 changed files
... ...
@@ -1838,10 +1838,10 @@ int check_boundaries(struct sip_msg *msg, struct dest_info *send_info)
1838 1838
 			tmp.len = get_line(lb_t->s);
1839 1839
 			if(tmp.len!=b.len || strncmp(b.s, tmp.s, b.len)!=0)
1840 1840
 			{
1841
-				LM_DBG("malformed bondary in the middle\n");
1841
+				LM_DBG("malformed boundary in the middle\n");
1842 1842
 				memcpy(pb, b.s, b.len); body.len = body.len + b.len;
1843 1843
 				pb = pb + b.len;
1844
-				t = lb_t->s.s - (lb_t->s.s + tmp.len);
1844
+				t = lb_t->next->s.s - (lb_t->s.s + tmp.len);
1845 1845
 				memcpy(pb, lb_t->s.s+tmp.len, t); pb = pb + t;
1846 1846
 				/*LM_DBG("new chunk[%d][%.*s]\n", t, t, pb-t);*/
1847 1847
 			}
Browse code

core : add word to log get_boundary function

added word to log for more understanding

Yasin CANER authored on 19/11/2018 07:00:40 • GitHub committed on 19/11/2018 07:00:40
Showing 1 changed files
... ...
@@ -1713,7 +1713,7 @@ int get_boundary(struct sip_msg* msg, str* boundary)
1713 1713
 		msg->content_type->body.len);
1714 1714
 	if (params.s == NULL)
1715 1715
 	{
1716
-		LM_INFO("Content-Type hdr has no params <%.*s>\n",
1716
+		LM_INFO("Content-Type hdr has no boundary params <%.*s>\n",
1717 1717
 				msg->content_type->body.len, msg->content_type->body.s);
1718 1718
 		return -1;
1719 1719
 	}
Browse code

core: new global parameter xavp_via_fields

- set the name of xavp from where to take Via header field: address and
port
- use them to build local Via header

Daniel-Constantin Mierla authored on 04/10/2018 14:45:14
Showing 1 changed files
... ...
@@ -114,6 +114,7 @@ extern char version[];
114 114
 extern int version_len;
115 115
 
116 116
 str _ksr_xavp_via_params = STR_NULL;
117
+str _ksr_xavp_via_fields = STR_NULL;
117 118
 
118 119
 /** per process fixup function for global_req_flags.
119 120
   * It should be called from the configuration framework.
... ...
@@ -2673,10 +2674,10 @@ int branch_builder( unsigned int hash_index,
2673 2674
 
2674 2675
 
2675 2676
 
2676
-/* uses only the send_info->send_socket, send_info->proto and 
2677
+/* uses only the send_info->send_socket, send_info->proto and
2677 2678
  * send_info->comp (so that a send_info used for sending can be passed
2678 2679
  * to this function w/o changes and the correct via will be built) */
2679
-char* via_builder( unsigned int *len,
2680
+char* via_builder(unsigned int *len, sip_msg_t *msg,
2680 2681
 	struct dest_info* send_info /* where to send the reply */,
2681 2682
 	str* branch, str* extra_params, struct hostport* hp)
2682 2683
 {
... ...
@@ -2684,8 +2685,8 @@ char* via_builder( unsigned int *len,
2684 2685
 	char               *line_buf;
2685 2686
 	int max_len;
2686 2687
 	int via_prefix_len;
2687
-	str* address_str; /* address displayed in via */
2688
-	str* port_str; /* port no displayed in via */
2688
+	str* address_str = NULL; /* address displayed in via */
2689
+	str* port_str = NULL; /* port no displayed in via */
2689 2690
 	struct socket_info* send_sock;
2690 2691
 	int comp_len, comp_name_len;
2691 2692
 #ifdef USE_COMP
... ...
@@ -2696,22 +2697,46 @@ char* via_builder( unsigned int *len,
2696 2697
 	union sockaddr_union *from = NULL;
2697 2698
 	union sockaddr_union local_addr;
2698 2699
 	struct tcp_connection *con = NULL;
2700
+	sr_xavp_t *rxavp = NULL;
2701
+	str xname;
2699 2702
 
2700 2703
 	send_sock=send_info->send_sock;
2701 2704
 	/* use pre-set address in via, the outbound socket alias or address one */
2702
-	if (hp && hp->host->len)
2703
-		address_str=hp->host;
2704
-	else if(send_sock->useinfo.name.len>0)
2705
-		address_str=&(send_sock->useinfo.name);
2706
-	else
2707
-		address_str=&(send_sock->address_str);
2708
-	if (hp && hp->port->len)
2709
-		port_str=hp->port;
2710
-	else if(send_sock->useinfo.port_no>0)
2711
-		port_str=&(send_sock->useinfo.port_no_str);
2712
-	else
2713
-		port_str=&(send_sock->port_no_str);
2714
-	
2705
+	if(msg && (msg->msg_flags&FL_USE_XAVP_VIA_FIELDS)
2706
+			&& _ksr_xavp_via_fields.len>0) {
2707
+		xname.s = "address";
2708
+		xname.len = 7;
2709
+		rxavp = xavp_get_child_with_sval(&_ksr_xavp_via_fields, &xname);
2710
+		if(rxavp!=NULL) {
2711
+			address_str = &rxavp->val.v.s;
2712
+		}
2713
+	}
2714
+	if(address_str==NULL) {
2715
+		if (hp && hp->host->len)
2716
+			address_str=hp->host;
2717
+		else if(send_sock->useinfo.name.len>0)
2718
+			address_str=&(send_sock->useinfo.name);
2719
+		else
2720
+			address_str=&(send_sock->address_str);
2721
+	}
2722
+	if(msg && (msg->msg_flags&FL_USE_XAVP_VIA_FIELDS)
2723
+			&& _ksr_xavp_via_fields.len>0) {
2724
+		xname.s = "port";
2725
+		xname.len = 4;
2726
+		rxavp = xavp_get_child_with_sval(&_ksr_xavp_via_fields, &xname);
2727
+		if(rxavp!=NULL) {
2728
+			port_str = &rxavp->val.v.s;
2729
+		}
2730
+	}
2731
+	if(port_str==NULL) {
2732
+		if (hp && hp->port->len)
2733
+			port_str=hp->port;
2734
+		else if(send_sock->useinfo.port_no>0)
2735
+			port_str=&(send_sock->useinfo.port_no_str);
2736
+		else
2737
+			port_str=&(send_sock->port_no_str);
2738
+	}
2739
+
2715 2740
 	comp_len=comp_name_len=0;
2716 2741
 #ifdef USE_COMP
2717 2742
 	comp_name=0;
... ...
@@ -2861,7 +2886,7 @@ char* via_builder( unsigned int *len,
2861 2886
 
2862 2887
 /* creates a via header honoring the protocol of the incoming socket
2863 2888
  * msg is an optional parameter */
2864
-char* create_via_hf( unsigned int *len,
2889
+char* create_via_hf(unsigned int *len,
2865 2890
 	struct sip_msg *msg,
2866 2891
 	struct dest_info* send_info /* where to send the reply */,
2867 2892
 	str* branch)
... ...
@@ -2982,7 +3007,7 @@ char* create_via_hf( unsigned int *len,
2982 3007
 	}
2983 3008
 
2984 3009
 	set_hostport(&hp, msg);
2985
-	via = via_builder( len, send_info, branch,
3010
+	via = via_builder(len, msg, send_info, branch,
2986 3011
 							extra_params.len?&extra_params:0, &hp);
2987 3012
 
2988 3013
 	/* we do not need extra_params any more, already in the new via header */
Browse code

core: renamed FL_ADD_XAVP_VIA to FL_ADD_XAVP_VIA_PARAMS

- match better the purpose of the internal flag

Daniel-Constantin Mierla authored on 04/10/2018 12:14:37
Showing 1 changed files
... ...
@@ -2955,7 +2955,8 @@ char* create_via_hf( unsigned int *len,
2955 2955
 	}
2956 2956
 
2957 2957
 	/* test and add xavp params */
2958
-	if(msg && (msg->msg_flags&FL_ADD_XAVP_VIA) && _ksr_xavp_via_params.len>0) {
2958
+	if(msg && (msg->msg_flags&FL_ADD_XAVP_VIA_PARAMS)
2959
+			&& _ksr_xavp_via_params.len>0) {
2959 2960
 		xparams.s = pv_get_buffer();
2960 2961
 		xparams.len = xavp_serialize_fields(&_ksr_xavp_via_params,
2961 2962
 							xparams.s, pv_get_buffer_size());
Browse code

core: fix comment typo

Mikko Lehto authored on 22/09/2018 07:21:19
Showing 1 changed files
... ...
@@ -2859,7 +2859,7 @@ char* via_builder( unsigned int *len,
2859 2859
 	return line_buf;
2860 2860
 }
2861 2861
 
2862
-/* creates a via header honoring the protocol of the incomming socket
2862
+/* creates a via header honoring the protocol of the incoming socket
2863 2863
  * msg is an optional parameter */
2864 2864
 char* create_via_hf( unsigned int *len,
2865 2865
 	struct sip_msg *msg,
Browse code

core: functions to apply changes and update internal sip msg buffer

Daniel-Constantin Mierla authored on 02/09/2018 10:33:17
Showing 1 changed files
... ...
@@ -3176,3 +3176,106 @@ int build_sip_msg_from_buf(struct sip_msg *msg, char *buf, int len,
3176 3176
 	return 0;
3177 3177
 }
3178 3178
 
3179
+/**
3180
+ *
3181
+ */
3182
+int sip_msg_update_buffer(sip_msg_t *msg, str *obuf)
3183
+{
3184
+	sip_msg_t tmp;
3185
+
3186
+	if(obuf==NULL || obuf->s==NULL || obuf->len<=0) {
3187
+		LM_ERR("invalid buffer parameter\n");
3188
+		return -1;
3189
+	}
3190
+
3191
+	if(obuf->len >= BUF_SIZE) {
3192
+		LM_ERR("new buffer is too large (%d)\n", obuf->len);
3193
+		return -1;
3194
+	}
3195
+	/* temporary copy */
3196
+	memcpy(&tmp, msg, sizeof(sip_msg_t));
3197
+
3198
+	/* reset dst uri and path vector to avoid freeing - restored later */
3199
+	if(msg->dst_uri.s != NULL) {
3200
+		msg->dst_uri.s = NULL;
3201
+		msg->dst_uri.len = 0;
3202
+	}
3203
+	if(msg->path_vec.s != NULL) {
3204
+		msg->path_vec.s = NULL;
3205
+		msg->path_vec.len = 0;
3206
+	}
3207
+
3208
+	/* free old msg structure */
3209
+	free_sip_msg(msg);
3210
+	memset(msg, 0, sizeof(sip_msg_t));
3211
+
3212
+	/* restore msg fields */
3213
+	msg->buf = tmp.buf;
3214
+	msg->id = tmp.id;
3215
+	msg->rcv = tmp.rcv;
3216
+	msg->set_global_address = tmp.set_global_address;
3217
+	msg->set_global_port = tmp.set_global_port;
3218
+	msg->flags = tmp.flags;
3219
+	msg->msg_flags = tmp.msg_flags;
3220
+	msg->hash_index = tmp.hash_index;
3221
+	msg->force_send_socket = tmp.force_send_socket;
3222
+	msg->fwd_send_flags = tmp.fwd_send_flags;
3223
+	msg->rpl_send_flags = tmp.rpl_send_flags;
3224
+	msg->dst_uri = tmp.dst_uri;
3225
+	msg->path_vec = tmp.path_vec;
3226
+
3227
+	memcpy(msg->buf, obuf->s, obuf->len);
3228
+	msg->len = obuf->len;
3229
+	msg->buf[msg->len] = '\0';
3230
+
3231
+	/* reparse the message */
3232
+	LM_DBG("SIP message content updated - reparsing\n");
3233
+	if(parse_msg(msg->buf, msg->len, msg) != 0) {
3234
+		LM_ERR("parsing new sip message failed [[%.*s]]\n", msg->len, msg->buf);
3235
+		/* exit config execution - sip_msg_t structure is no longer
3236
+		 * valid/safe for config */
3237
+		return 0;
3238
+	}
3239
+
3240
+	return 1;
3241
+}
3242
+
3243
+/**
3244
+ *
3245
+ */
3246
+int sip_msg_apply_changes(sip_msg_t *msg)
3247
+{
3248
+	int ret;
3249
+	dest_info_t dst;
3250
+	str obuf;
3251
+
3252
+	if(msg->first_line.type != SIP_REPLY && get_route_type() != REQUEST_ROUTE) {
3253
+		LM_ERR("invalid usage - not in request route or a reply\n");
3254
+		return -1;
3255
+	}
3256
+
3257
+	init_dest_info(&dst);
3258
+	dst.proto = PROTO_UDP;
3259
+	if(msg->first_line.type == SIP_REPLY) {
3260
+		obuf.s = generate_res_buf_from_sip_res(
3261
+				msg, (unsigned int *)&obuf.len, BUILD_NO_VIA1_UPDATE);
3262
+	} else {
3263
+		if(msg->msg_flags & FL_RR_ADDED) {
3264
+			LM_ERR("cannot apply msg changes after adding record-route"
3265
+				   " header - it breaks conditional 2nd header\n");
3266
+			return -1;
3267
+		}
3268
+		obuf.s = build_req_buf_from_sip_req(msg, (unsigned int *)&obuf.len,
3269
+				&dst,
3270
+				BUILD_NO_PATH | BUILD_NO_LOCAL_VIA | BUILD_NO_VIA1_UPDATE);
3271
+	}
3272
+	if(obuf.s == NULL) {
3273
+		LM_ERR("couldn't update msg buffer content\n");
3274
+		return -1;
3275
+	}
3276
+	ret = sip_msg_update_buffer(msg, &obuf);
3277
+	/* free new buffer - copied in the static buffer from old sip_msg_t */
3278
+	pkg_free(obuf.s);
3279
+
3280
+	return ret;
3281
+}
Browse code

core: test if address for IPv6 is IP format in lump substitutions

- reported by GH #1581

Daniel-Constantin Mierla authored on 04/07/2018 07:18:52
Showing 1 changed files
... ...
@@ -646,7 +646,10 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
646 646
 			case SUBST_RCV_ALL: \
647 647
 				if (msg->rcv.bind_address){ \
648 648
 					new_len+=recv_address_str->len; \
649
-					if (msg->rcv.bind_address->address.af!=AF_INET) \
649
+					if ((msg->rcv.bind_address->address.af==AF_INET6)\
650
+							&& (recv_address_str->s[0]!='[')\
651
+							&& (memchr(recv_address_str->s, ':',\
652
+								recv_address_str->len)!=NULL))\
650 653
 						new_len+=2; \
651 654
 					if (recv_port_no!=SIP_PORT){ \
652 655
 						/* add :port_no */ \
... ...
@@ -732,7 +735,9 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
732 735
 				if (send_sock){ \
733 736
 					new_len+=send_address_str->len; \
734 737
 					if ((send_sock->address.af==AF_INET6) && \
735
-							(send_address_str->s[0]!='[')) \
738
+							(send_address_str->s[0]!='[')\
739
+							&& (memchr(send_address_str->s, ':',\
740
+								send_address_str->len)!=NULL)) \
736 741
 						new_len+=2; \
737 742
 					if ((send_sock->port_no!=SIP_PORT) || \
738 743
 							(send_port_str!=&(send_sock->port_no_str))){ \
... ...
@@ -1000,13 +1005,19 @@ void process_lumps( struct sip_msg* msg,
1000 1005
 		case SUBST_RCV_ALL: \
1001 1006
 			if (msg->rcv.bind_address){  \
1002 1007
 				/* address */ \
1003
-				if (msg->rcv.bind_address->address.af!=AF_INET){\
1008
+				if ((msg->rcv.bind_address->address.af==AF_INET6)\
1009
+						&& (recv_address_str->s[0]!='[')\
1010
+						&& (memchr(recv_address_str->s, ':',\
1011
+								recv_address_str->len)!=NULL)){\
1004 1012
 					new_buf[offset]='['; offset++; \
1005 1013
 				}\
1006 1014
 				memcpy(new_buf+offset, recv_address_str->s, \
1007 1015
 						recv_address_str->len); \
1008 1016
 				offset+=recv_address_str->len; \
1009
-				if (msg->rcv.bind_address->address.af!=AF_INET){\
1017
+				if ((msg->rcv.bind_address->address.af==AF_INET6)\
1018
+						&& (recv_address_str->s[0]!='[')\
1019
+						&& (memchr(recv_address_str->s, ':',\
1020
+								recv_address_str->len)!=NULL)){\
1010 1021
 					new_buf[offset]=']'; offset++; \
1011 1022
 				}\
1012 1023
 				/* :port */ \
... ...
@@ -1092,15 +1103,19 @@ void process_lumps( struct sip_msg* msg,
1092 1103
 		case SUBST_SND_ALL: \
1093 1104
 			if (send_sock){  \
1094 1105
 				/* address */ \
1095
-				if ((send_sock->address.af!=AF_INET) && \
1096
-						(send_address_str->s[0]!='[')){\
1106
+				if ((send_sock->address.af==AF_INET6)\
1107
+						&& (send_address_str->s[0]!='[')\
1108
+						&& (memchr(send_address_str->s, ':',\
1109
+								send_address_str->len)!=NULL)){\
1097 1110
 					new_buf[offset]='['; offset++; \
1098 1111
 				}\
1099 1112
 				memcpy(new_buf+offset, send_address_str->s, \
1100 1113
 						send_address_str->len); \
1101 1114
 				offset+=send_address_str->len; \
1102
-				if ((send_sock->address.af!=AF_INET) && \
1103