Module: kamailio
Branch: master
Commit: 2e46081424240dfb3767da74b0818249dff46802
URL:
https://github.com/kamailio/kamailio/commit/2e46081424240dfb3767da74b081824…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-01-11T11:53:35+01:00
siptrace: replaced sequeces of string concatenations with safer formatted print
- used to build proxy-like addresses
---
Modified: src/modules/siptrace/siptrace.c
Modified: src/modules/siptrace/siptrace_send.c
Modified: src/modules/siptrace/siptrace_send.h
---
Diff:
https://github.com/kamailio/kamailio/commit/2e46081424240dfb3767da74b081824…
Patch:
https://github.com/kamailio/kamailio/commit/2e46081424240dfb3767da74b081824…
---
diff --git a/src/modules/siptrace/siptrace.c b/src/modules/siptrace/siptrace.c
index 0df1e959fb..d8b5da399b 100644
--- a/src/modules/siptrace/siptrace.c
+++ b/src/modules/siptrace/siptrace.c
@@ -1339,12 +1339,16 @@ static void trace_sl_onreply_out(sl_cbp_t *slcbp)
if(trace_local_ip.len > 0) {
sto.fromip = trace_local_ip;
} else {
- siptrace_copy_proto(msg->rcv.proto, sto.fromip_buff);
- strcat(sto.fromip_buff, ip_addr2a(&req->rcv.dst_ip));
- strcat(sto.fromip_buff, ":");
- strcat(sto.fromip_buff, int2str(req->rcv.dst_port, NULL));
- sto.fromip.s = sto.fromip_buff;
- sto.fromip.len = strlen(sto.fromip_buff);
+ sto.fromip.len = snprintf(sto.fromip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d",
+ siptrace_proto_name(req->rcv.proto),
+ ip_addr2a(&req->rcv.dst_ip), req->rcv.dst_port);
+ if(sto.fromip.len<0 || sto.fromip.len>=SIPTRACE_ADDR_MAX) {
+ LM_ERR("failed to format toip buffer (%d)\n", sto.fromip.len);
+ sto.fromip.s = "any:255.255.255.255";
+ sto.fromip.len = 19;
+ } else {
+ sto.fromip.s = sto.fromip_buff;
+ }
}
strcpy(statusbuf, int2str(slcbp->code, &sto.status.len));
@@ -1356,13 +1360,16 @@ static void trace_sl_onreply_out(sl_cbp_t *slcbp)
sto.toip.len = 19;
} else {
su2ip_addr(&to_ip, &slcbp->dst->to);
- siptrace_copy_proto(req->rcv.proto, sto.toip_buff);
- strcat(sto.toip_buff, ip_addr2a(&to_ip));
- strcat(sto.toip_buff, ":");
- strcat(sto.toip_buff,
- int2str((unsigned long)su_getport(&slcbp->dst->to), &len));
- sto.toip.s = sto.toip_buff;
- sto.toip.len = strlen(sto.toip_buff);
+ sto.toip.len = snprintf(sto.toip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d",
+ siptrace_proto_name(req->rcv.proto), ip_addr2a(&to_ip),
+ (int)su_getport(&slcbp->dst->to));
+ if(sto.toip.len<0 || sto.toip.len>=SIPTRACE_ADDR_MAX) {
+ LM_ERR("failed to format toip buffer (%d)\n", sto.toip.len);
+ sto.toip.s = "any:255.255.255.255";
+ sto.toip.len = 19;
+ } else {
+ sto.toip.s = sto.toip_buff;
+ }
}
sto.dir = "out";
diff --git a/src/modules/siptrace/siptrace_send.c b/src/modules/siptrace/siptrace_send.c
index eeb91c20c7..6e7718b933 100644
--- a/src/modules/siptrace/siptrace_send.c
+++ b/src/modules/siptrace/siptrace_send.c
@@ -318,3 +318,24 @@ int trace_send_duplicate(char *buf, int len, struct dest_info *dst2)
}
return -1;
}
+
+/**
+ *
+ */
+char* siptrace_proto_name(int vproto)
+{
+ switch(vproto) {
+ case PROTO_TCP:
+ return "tcp";
+ case PROTO_TLS:
+ return "tls";
+ case PROTO_SCTP:
+ return "sctp";
+ case PROTO_WS:
+ return "ws";
+ case PROTO_WSS:
+ return "wss";
+ default:
+ return "udp";
+ }
+}
diff --git a/src/modules/siptrace/siptrace_send.h b/src/modules/siptrace/siptrace_send.h
index a83eebad22..30c33e53b5 100644
--- a/src/modules/siptrace/siptrace_send.h
+++ b/src/modules/siptrace/siptrace_send.h
@@ -70,4 +70,6 @@ int trace_send_duplicate(char *buf, int len, struct dest_info *dst2);
siptrace_copy_proto_olen(vproto, vbuf, __olen); \
} while(0)
-#endif
+char* siptrace_proto_name(int vproto);
+
+#endif
\ No newline at end of file