Module: kamailio
Branch: master
Commit: 1de15c06b982b4b4a0d9860b51c2178745cd9af0
URL:
https://github.com/kamailio/kamailio/commit/1de15c06b982b4b4a0d9860b51c2178…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-11-01T16:46:20+01:00
core: safety checks to catch enclosed ipv6 addresses or hostnames in via build
---
Modified: src/core/msg_translator.c
---
Diff:
https://github.com/kamailio/kamailio/commit/1de15c06b982b4b4a0d9860b51c2178…
Patch:
https://github.com/kamailio/kamailio/commit/1de15c06b982b4b4a0d9860b51c2178…
---
diff --git a/src/core/msg_translator.c b/src/core/msg_translator.c
index 3a24aa077a..725d6290c9 100644
--- a/src/core/msg_translator.c
+++ b/src/core/msg_translator.c
@@ -2788,10 +2788,15 @@ char* via_builder( unsigned int *len,
/* add [] only if ipv6 address is used;
* if using pre-set no check is made */
if (send_sock->address.af==AF_INET6) {
- line_buf[via_prefix_len]='[';
- line_buf[via_prefix_len+1+address_str->len]=']';
- extra_len=1;
- via_len+=2; /* [ ]*/
+ /* lightweight safety checks if brackets set
+ * or non-ipv6 (e.g., advertised hostname) */
+ if(address_str->s[0] != '['
+ && memchr(address_str->s, ':', address_str->len)!=NULL) {
+ line_buf[via_prefix_len]='[';
+ line_buf[via_prefix_len+1+address_str->len]=']';
+ extra_len=1;
+ via_len+=2; /* [ ]*/
+ }
}
memcpy(line_buf+via_prefix_len+extra_len, address_str->s,
address_str->len);