Module: kamailio
Branch: master
Commit: 7ef0a272dc9c81afa05ef8b1591e9f05c2810e9a
URL:
https://github.com/kamailio/kamailio/commit/7ef0a272dc9c81afa05ef8b1591e9f0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2021-04-07T11:33:24+02:00
core: check for non empty receive address and port in msg translator
---
Modified: src/core/msg_translator.c
Modified: src/core/str.h
---
Diff:
https://github.com/kamailio/kamailio/commit/7ef0a272dc9c81afa05ef8b1591e9f0…
Patch:
https://github.com/kamailio/kamailio/commit/7ef0a272dc9c81afa05ef8b1591e9f0…
---
diff --git a/src/core/msg_translator.c b/src/core/msg_translator.c
index 4622b264d5..a2f6505e83 100644
--- a/src/core/msg_translator.c
+++ b/src/core/msg_translator.c
@@ -597,7 +597,7 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
#define SUBST_LUMP_LEN(subst_l) \
switch((subst_l)->u.subst){ \
case SUBST_RCV_IP: \
- if (msg->rcv.bind_address){ \
+ if (msg->rcv.bind_address && STR_WITHVAL(recv_address_str)){ \
new_len+=recv_address_str->len; \
if (msg->rcv.bind_address->address.af!=AF_INET) \
new_len+=2; \
@@ -607,7 +607,7 @@ static inline int lumps_len(struct sip_msg* msg, struct lump* lumps,
}; \
break; \
case SUBST_RCV_PORT: \
- if (msg->rcv.bind_address){ \
+ if (msg->rcv.bind_address && STR_WITHVAL(recv_port_str)){ \
new_len+=recv_port_str->len; \
}else{ \
/* FIXME */ \
@@ -646,14 +646,14 @@ static inline int lumps_len(struct sip_msg* msg, struct lump*
lumps,
break; \
case SUBST_RCV_ALL: \
case SUBST_RCV_ALL_EX: \
- if (msg->rcv.bind_address){ \
+ if (msg->rcv.bind_address && STR_WITHVAL(recv_address_str)){ \
new_len+=recv_address_str->len; \
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){ \
+ if (recv_port_no!=SIP_PORT && STR_WITHVAL(recv_port_str)){ \
/* add :port_no */ \
new_len+=1+recv_port_str->len; \
}\
@@ -990,7 +990,7 @@ void process_lumps( struct sip_msg* msg,
#define SUBST_LUMP(subst_l) \
switch((subst_l)->u.subst){ \
case SUBST_RCV_IP: \
- if (msg->rcv.bind_address){ \
+ if (msg->rcv.bind_address && STR_WITHVAL(recv_address_str)){ \
if (msg->rcv.bind_address->address.af!=AF_INET){\
new_buf[offset]='['; offset++; \
}\
@@ -1006,7 +1006,7 @@ void process_lumps( struct sip_msg* msg,
}; \
break; \
case SUBST_RCV_PORT: \
- if (msg->rcv.bind_address){ \
+ if (msg->rcv.bind_address && STR_WITHVAL(recv_port_str)){ \
memcpy(new_buf+offset, recv_port_str->s, \
recv_port_str->len); \
offset+=recv_port_str->len; \
@@ -1017,7 +1017,7 @@ void process_lumps( struct sip_msg* msg,
break; \
case SUBST_RCV_ALL: \
case SUBST_RCV_ALL_EX: \
- if (msg->rcv.bind_address){ \
+ if (msg->rcv.bind_address && STR_WITHVAL(recv_address_str)){ \
/* address */ \
if ((msg->rcv.bind_address->address.af==AF_INET6)\
&& (recv_address_str->s[0]!='[')\
@@ -1035,7 +1035,7 @@ void process_lumps( struct sip_msg* msg,
new_buf[offset]=']'; offset++; \
}\
/* :port */ \
- if (recv_port_no!=SIP_PORT){ \
+ if (recv_port_no!=SIP_PORT && STR_WITHVAL(recv_port_str)){ \
new_buf[offset]=':'; offset++; \
memcpy(new_buf+offset, \
recv_port_str->s, \
diff --git a/src/core/str.h b/src/core/str.h
index 58d7d627f6..d7977652d9 100644
--- a/src/core/str.h
+++ b/src/core/str.h
@@ -142,6 +142,11 @@ typedef struct _str str;
} \
} while(0)
+/**
+ * str with value: not null and not emptu
+ */
+#define STR_WITHVAL(_sp) ((_sp) && ((_sp)->s) && ((_sp)->len))
+
/** @} */
/** Appends a sufffix