Browse code

core: test if ipv6 address starts with [ for subst snd lumps

- safer than the test against cached socket address known to be without
[], allowing to pass any address value to be used
- reported by GH #1315

Daniel-Constantin Mierla authored on 17/11/2017 13:33:46
Showing 1 changed files
... ...
@@ -678,8 +678,8 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
678 678
 			case SUBST_SND_IP: \
679 679
 				if (send_sock){ \
680 680
 					new_len+=send_address_str->len; \
681
-					if (send_sock->address.af!=AF_INET && \
682
-							send_address_str==&(send_sock->address_str)) \
681
+					if (send_sock->address.af==AF_INET6 && \
682
+							send_address_str->s[0]!='[') \
683 683
 						new_len+=2; \
684 684
 				}else{ \
685 685
 					LM_CRIT("FIXME: null send_sock\n"); \
... ...
@@ -724,8 +724,8 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
724 724
 			case SUBST_SND_ALL: \
725 725
 				if (send_sock){ \
726 726
 					new_len+=send_address_str->len; \
727
-					if ((send_sock->address.af!=AF_INET) && \
728
-							(send_address_str==&(send_sock->address_str))) \
727
+					if ((send_sock->address.af==AF_INET6) && \
728
+							(send_address_str->s[0]!='[')) \
729 729
 						new_len+=2; \
730 730
 					if ((send_sock->port_no!=SIP_PORT) || \
731 731
 							(send_port_str!=&(send_sock->port_no_str))){ \
... ...
@@ -766,7 +766,7 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
766 766
 			default: \
767 767
 				LM_CRIT("unknown subst type %d\n", (subst_l)->u.subst); \
768 768
 		}
769
-	
769
+
770 770
 	if (send_info){
771 771
 		send_sock=send_info->send_sock;
772 772
 	}else{
... ...
@@ -935,7 +935,7 @@ void process_lumps( struct sip_msg* msg,
935 935
 					default:\
936 936
 						LM_CRIT("unknown comp %d\n", msg->rcv.comp); \
937 937
 				}
938
-	
938
+
939 939
 	#define SENDCOMP_PARAM_ADD \
940 940
 				/* add ;comp=xxxx */ \
941 941
 				switch(send_info->comp){ \
... ...
@@ -956,7 +956,7 @@ void process_lumps( struct sip_msg* msg,
956 956
 						break;\
957 957
 					default:\
958 958
 						LM_CRIT("unknown comp %d\n", msg->rcv.comp); \
959
-				} 
959
+				}
960 960
 #else
961 961
 	#define RCVCOMP_PARAM_ADD
962 962
 	#define SENDCOMP_PARAM_ADD
... ...
@@ -1057,14 +1057,14 @@ void process_lumps( struct sip_msg* msg,
1057 1057
 		case SUBST_SND_IP: \
1058 1058
 			if (send_sock){  \
1059 1059
 				if ((send_sock->address.af!=AF_INET) && \
1060
-						(send_address_str==&(send_sock->address_str))){\
1060
+						(send_address_str->s[0]!='[')){\
1061 1061
 					new_buf[offset]='['; offset++; \
1062 1062
 				}\
1063 1063
 				memcpy(new_buf+offset, send_address_str->s, \
1064 1064
 									send_address_str->len); \
1065 1065
 				offset+=send_address_str->len; \
1066 1066
 				if ((send_sock->address.af!=AF_INET) && \
1067
-						(send_address_str==&(send_sock->address_str))){\
1067
+						(send_address_str->s[0]!='[')){\
1068 1068
 					new_buf[offset]=']'; offset++; \
1069 1069
 				}\
1070 1070
 			}else{  \
... ...
@@ -1086,14 +1086,14 @@ void process_lumps( struct sip_msg* msg,
1086 1086
 			if (send_sock){  \
1087 1087
 				/* address */ \
1088 1088
 				if ((send_sock->address.af!=AF_INET) && \
1089
-						(send_address_str==&(send_sock->address_str))){\
1089
+						(send_address_str->s[0]!='[')){\
1090 1090
 					new_buf[offset]='['; offset++; \
1091 1091
 				}\
1092 1092
 				memcpy(new_buf+offset, send_address_str->s, \
1093 1093
 						send_address_str->len); \
1094 1094
 				offset+=send_address_str->len; \
1095 1095
 				if ((send_sock->address.af!=AF_INET) && \
1096
-						(send_address_str==&(send_sock->address_str))){\
1096
+						(send_address_str->s[0]!='[')){\
1097 1097
 					new_buf[offset]=']'; offset++; \
1098 1098
 				}\
1099 1099
 				/* :port */ \