Browse code

core: safety checks to catch enclosed ipv6 addresses or hostnames in via build

Daniel-Constantin Mierla authored on 01/11/2017 15:46:20
Showing 1 changed files
... ...
@@ -2788,10 +2788,15 @@ char* via_builder( unsigned int *len,
2788 2788
 	/* add [] only if ipv6 address is used;
2789 2789
 	 * if using pre-set no check is made */
2790 2790
 	if (send_sock->address.af==AF_INET6) {
2791
-		line_buf[via_prefix_len]='[';
2792
-		line_buf[via_prefix_len+1+address_str->len]=']';
2793
-		extra_len=1;
2794
-		via_len+=2; /* [ ]*/
2791
+		/* lightweight safety checks if brackets set
2792
+		 * or non-ipv6 (e.g., advertised hostname) */
2793
+		if(address_str->s[0] != '['
2794
+				&& memchr(address_str->s, ':', address_str->len)!=NULL) {
2795
+			line_buf[via_prefix_len]='[';
2796
+			line_buf[via_prefix_len+1+address_str->len]=']';
2797
+			extra_len=1;
2798
+			via_len+=2; /* [ ]*/
2799
+		}
2795 2800
 	}
2796 2801
 	memcpy(line_buf+via_prefix_len+extra_len, address_str->s,
2797 2802
 				address_str->len);