Module: kamailio
Branch: master
Commit: 1d78456562418b785126af09761c12571ef2394d
URL:
https://github.com/kamailio/kamailio/commit/1d78456562418b785126af09761c125…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-07-04T09:18:52+02:00
core: test if address for IPv6 is IP format in lump substitutions
- reported by GH #1581
---
Modified: src/core/msg_translator.c
---
Diff:
https://github.com/kamailio/kamailio/commit/1d78456562418b785126af09761c125…
Patch:
https://github.com/kamailio/kamailio/commit/1d78456562418b785126af09761c125…
---
diff --git a/src/core/msg_translator.c b/src/core/msg_translator.c
index 88019b869b..f82d72c3cb 100644
--- a/src/core/msg_translator.c
+++ b/src/core/msg_translator.c
@@ -646,7 +646,10 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
case SUBST_RCV_ALL: \
if (msg->rcv.bind_address){ \
new_len+=recv_address_str->len; \
- if (msg->rcv.bind_address->address.af!=AF_INET) \
+ if ((msg->rcv.bind_address->address.af==AF_INET6)\
+ && (recv_address_str->s[0]!='[')\
+ && (memchr(recv_address_str->s, ':',\
+ recv_address_str->len)!=NULL))\
new_len+=2; \
if (recv_port_no!=SIP_PORT){ \
/* add :port_no */ \
@@ -732,7 +735,9 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
if (send_sock){ \
new_len+=send_address_str->len; \
if ((send_sock->address.af==AF_INET6) && \
- (send_address_str->s[0]!='[')) \
+ (send_address_str->s[0]!='[')\
+ && (memchr(send_address_str->s, ':',\
+ send_address_str->len)!=NULL)) \
new_len+=2; \
if ((send_sock->port_no!=SIP_PORT) || \
(send_port_str!=&(send_sock->port_no_str))){ \
@@ -1000,13 +1005,19 @@ void process_lumps( struct sip_msg* msg,
case SUBST_RCV_ALL: \
if (msg->rcv.bind_address){ \
/* address */ \
- if (msg->rcv.bind_address->address.af!=AF_INET){\
+ if ((msg->rcv.bind_address->address.af==AF_INET6)\
+ && (recv_address_str->s[0]!='[')\
+ && (memchr(recv_address_str->s, ':',\
+ recv_address_str->len)!=NULL)){\
new_buf[offset]='['; offset++; \
}\
memcpy(new_buf+offset, recv_address_str->s, \
recv_address_str->len); \
offset+=recv_address_str->len; \
- if (msg->rcv.bind_address->address.af!=AF_INET){\
+ if ((msg->rcv.bind_address->address.af==AF_INET6)\
+ && (recv_address_str->s[0]!='[')\
+ && (memchr(recv_address_str->s, ':',\
+ recv_address_str->len)!=NULL)){\
new_buf[offset]=']'; offset++; \
}\
/* :port */ \
@@ -1092,15 +1103,19 @@ void process_lumps( struct sip_msg* msg,
case SUBST_SND_ALL: \
if (send_sock){ \
/* address */ \
- if ((send_sock->address.af!=AF_INET) && \
- (send_address_str->s[0]!='[')){\
+ if ((send_sock->address.af==AF_INET6)\
+ && (send_address_str->s[0]!='[')\
+ && (memchr(send_address_str->s, ':',\
+ send_address_str->len)!=NULL)){\
new_buf[offset]='['; offset++; \
}\
memcpy(new_buf+offset, send_address_str->s, \
send_address_str->len); \
offset+=send_address_str->len; \
- if ((send_sock->address.af!=AF_INET) && \
- (send_address_str->s[0]!='[')){\
+ if ((send_sock->address.af==AF_INET6)\
+ && (send_address_str->s[0]!='[')\
+ && (memchr(send_address_str->s, ':',\
+ send_address_str->len)!=NULL)){\
new_buf[offset]=']'; offset++; \
}\
/* :port */ \