Selaa lähdekoodia

siptrace: convert status code to string using static buffer function

Daniel-Constantin Mierla 6 vuotta sitten
vanhempi
commit
95d56e986e
1 muutettua tiedostoa jossa 18 lisäystä ja 9 poistoa
  1. 18 9
      src/modules/siptrace/siptrace.c

+ 18 - 9
src/modules/siptrace/siptrace.c

@@ -1136,7 +1136,7 @@ static void trace_onreply_in(struct cell *t, int type, struct tmcb_params *ps)
 	siptrace_data_t sto;
 	sip_msg_t *msg;
 	sip_msg_t *req;
-	char statusbuf[8];
+	char statusbuf[INT2STR_MAX_LEN];
 
 	if(t == NULL || t->uas.request == 0 || ps == NULL) {
 		LM_DBG("no uas request, local transaction\n");
@@ -1170,8 +1170,11 @@ static void trace_onreply_in(struct cell *t, int type, struct tmcb_params *ps)
 
 	sto.method = get_cseq(msg)->method;
 
-	strcpy(statusbuf, int2str(ps->code, &sto.status.len));
-	sto.status.s = statusbuf;
+	sto.status.s = int2strbuf(ps->code, statusbuf, INT2STR_MAX_LEN, &sto.status.len);
+	if(sto.status.s == 0) {
+		LM_ERR("failure to get the status string\n");
+		return;
+	}
 
 	sto.fromip.len = snprintf(sto.fromip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d",
 			siptrace_proto_name(msg->rcv.proto),
@@ -1218,7 +1221,7 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps)
 	struct sip_msg *msg;
 	struct sip_msg *req;
 	struct ip_addr to_ip;
-	char statusbuf[8];
+	char statusbuf[INT2STR_MAX_LEN];
 	dest_info_t *dst;
 
 	if(t == NULL || t->uas.request == 0 || ps == NULL) {
@@ -1293,8 +1296,11 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps)
 		}
 	}
 
-	strcpy(statusbuf, int2str(ps->code, &sto.status.len));
-	sto.status.s = statusbuf;
+	sto.status.s = int2strbuf(ps->code, statusbuf, INT2STR_MAX_LEN, &sto.status.len);
+	if(sto.status.s == 0) {
+		LM_ERR("failure to get the status string\n");
+		return;
+	}
 
 	memset(&to_ip, 0, sizeof(struct ip_addr));
 	dst = ps->dst;
@@ -1341,7 +1347,7 @@ static void trace_sl_onreply_out(sl_cbp_t *slcbp)
 	siptrace_data_t sto;
 	sip_msg_t *msg;
 	ip_addr_t to_ip;
-	char statusbuf[5];
+	char statusbuf[INT2STR_MAX_LEN];
 
 	if(slcbp == NULL || slcbp->req == NULL) {
 		LM_ERR("bad parameters\n");
@@ -1385,8 +1391,11 @@ static void trace_sl_onreply_out(sl_cbp_t *slcbp)
 		}
 	}
 
-	strcpy(statusbuf, int2str(slcbp->code, &sto.status.len));
-	sto.status.s = statusbuf;
+	sto.status.s = int2strbuf(slcbp->code, statusbuf, INT2STR_MAX_LEN, &sto.status.len);
+	if(sto.status.s == 0) {
+		LM_ERR("failure to get the status string\n");
+		return;
+	}
 
 	memset(&to_ip, 0, sizeof(struct ip_addr));
 	if(slcbp->dst == 0) {