Skip to content

Commit

Permalink
siptrace: replaced sequeces of string concatenations with safer forma…
Browse files Browse the repository at this point in the history
…tted print

- used to build proxy-like addresses

(cherry picked from commit 2e46081)
  • Loading branch information
miconda committed Jan 19, 2018
1 parent 03d584a commit 53e21ff
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
33 changes: 20 additions & 13 deletions src/modules/siptrace/siptrace.c
Expand Up @@ -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));
Expand All @@ -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";
Expand Down
21 changes: 21 additions & 0 deletions src/modules/siptrace/siptrace_send.c
Expand Up @@ -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";
}
}
4 changes: 3 additions & 1 deletion src/modules/siptrace/siptrace_send.h
Expand Up @@ -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

0 comments on commit 53e21ff

Please sign in to comment.