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 2 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, \
... ...
@@ -142,6 +142,11 @@ typedef struct _str str;
142 142
 		} \
143 143
 	} while(0)
144 144
 
145
+/**
146
+ * str with value: not null and not emptu
147
+ */
148
+#define STR_WITHVAL(_sp) ((_sp) && ((_sp)->s) && ((_sp)->len))
149
+
145 150
 /** @} */
146 151
 
147 152
 /** Appends a sufffix