From 2e46081424240dfb3767da74b0818249dff46802 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Thu, 11 Jan 2018 11:44:51 +0100 Subject: [PATCH] siptrace: replaced sequeces of string concatenations with safer formatted print - used to build proxy-like addresses --- src/modules/siptrace/siptrace.c | 33 +++++++++++++++++----------- src/modules/siptrace/siptrace_send.c | 21 ++++++++++++++++++ src/modules/siptrace/siptrace_send.h | 4 +++- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/modules/siptrace/siptrace.c b/src/modules/siptrace/siptrace.c index 0df1e959fb8..d8b5da399ba 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 eeb91c20c70..6e7718b9331 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 a83eebad222..30c33e53b5d 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