Browse code

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

(cherry picked from commit 7ef0a272dc9c81afa05ef8b1591e9f05c2810e9a)

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