From 1062d636fe3a5b79b0ee789e36fd205ea4b87fb3 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Thu, 27 Sep 2018 14:34:41 +0200 Subject: [PATCH] presence:use memcpy() instead of strncpy() > subscribe.c: In function 'send_2XX_reply': > subscribe.c:74:2: warning: 'strncpy' output truncated before terminating nul copying 9 bytes from a string of the same length [-Wstringop-truncation] > strncpy(hdr_append.s, "Expires: ", 9); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > subscribe.c:77:2: warning: 'strncpy' output truncated before terminating nul copying 2 bytes from a string of the same length [-Wstringop-truncation] > strncpy(tmp.s, CRLF, CRLF_LEN); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > subscribe.c:79:2: warning: 'strncpy' output truncated before terminating nul copying 10 bytes from a string of the same length [-Wstringop-truncation] > strncpy(tmp.s, "Contact: <", 10); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > subscribe.c:90:5: warning: 'strncpy' output truncated before terminating nul copying 14 bytes from a string of the same length [-Wstringop-truncation] > strncpy(tmp.s, ";transport=tcp", 14); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > subscribe.c:95:5: warning: 'strncpy' output truncated before terminating nul copying 14 bytes from a string of the same length [-Wstringop-truncation] > strncpy(tmp.s, ";transport=tls", 14); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > subscribe.c:100:5: warning: 'strncpy' output truncated before terminating nul copying 15 bytes from a string of the same length [-Wstringop-truncation] > strncpy(tmp.s, ";transport=sctp", 15); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > subscribe.c:105:5: warning: 'strncpy' output truncated before terminating nul copying 13 bytes from a string of the same length [-Wstringop-truncation] > strncpy(tmp.s, ";transport=ws", 13); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > subscribe.c:116:2: warning: 'strncpy' output truncated before terminating nul copying 2 bytes from a string of the same length [-Wstringop-truncation] > strncpy(tmp.s+1, CRLF, CRLF_LEN); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > In file included from subscribe.c:39: > utils_func.h: In function 'ps_fill_local_contact': > utils_func.h:142:3: warning: 'strncpy' output truncated before terminating nul copying 4 bytes from a string of the same length [-Wstringop-truncation] > strncpy(p, "sip:", 4); > ^~~~~~~~~~~~~~~~~~~~~ --- src/modules/presence/subscribe.c | 20 ++++++++++---------- src/modules/presence/utils_func.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/modules/presence/subscribe.c b/src/modules/presence/subscribe.c index e3352b16157..e5d8c62d308 100644 --- a/src/modules/presence/subscribe.c +++ b/src/modules/presence/subscribe.c @@ -71,14 +71,14 @@ static int send_2XX_reply(sip_msg_t *msg, int reply_code, { ERR_MEM(PKG_MEM_STR); } - strncpy(hdr_append.s, "Expires: ", 9); - strncpy(hdr_append.s+9, tmp.s, tmp.len); + memcpy(hdr_append.s, "Expires: ", 9); + memcpy(hdr_append.s+9, tmp.s, tmp.len); tmp.s = hdr_append.s+9+tmp.len; - strncpy(tmp.s, CRLF, CRLF_LEN); + memcpy(tmp.s, CRLF, CRLF_LEN); tmp.s += CRLF_LEN; - strncpy(tmp.s, "Contact: <", 10); + memcpy(tmp.s, "Contact: <", 10); tmp.s += 10; - strncpy(tmp.s, local_contact->s, local_contact->len); + memcpy(tmp.s, local_contact->s, local_contact->len); tmp.s[local_contact->len] = '\0'; t = strstr(tmp.s, ";transport="); tmp.s += local_contact->len; @@ -87,22 +87,22 @@ static int send_2XX_reply(sip_msg_t *msg, int reply_code, switch (msg->rcv.proto) { case PROTO_TCP: - strncpy(tmp.s, ";transport=tcp", 14); + memcpy(tmp.s, ";transport=tcp", 14); tmp.s += 14; hdr_append.len -= 1; break; case PROTO_TLS: - strncpy(tmp.s, ";transport=tls", 14); + memcpy(tmp.s, ";transport=tls", 14); tmp.s += 14; hdr_append.len -= 1; break; case PROTO_SCTP: - strncpy(tmp.s, ";transport=sctp", 15); + memcpy(tmp.s, ";transport=sctp", 15); tmp.s += 15; break; case PROTO_WS: case PROTO_WSS: - strncpy(tmp.s, ";transport=ws", 13); + memcpy(tmp.s, ";transport=ws", 13); tmp.s += 13; hdr_append.len -= 2; break; @@ -113,7 +113,7 @@ static int send_2XX_reply(sip_msg_t *msg, int reply_code, hdr_append.len -= 15; } *tmp.s = '>'; - strncpy(tmp.s+1, CRLF, CRLF_LEN); + memcpy(tmp.s+1, CRLF, CRLF_LEN); hdr_append.s[hdr_append.len]= '\0'; diff --git a/src/modules/presence/utils_func.h b/src/modules/presence/utils_func.h index b68890f21ce..bfc8c5654f6 100644 --- a/src/modules/presence/utils_func.h +++ b/src/modules/presence/utils_func.h @@ -139,7 +139,7 @@ static inline int ps_fill_local_contact(struct sip_msg* msg, str *contact) p = contact->s; if(strncmp(ip.s, "sip:", 4)!=0) { - strncpy(p, "sip:", 4); + memcpy(p, "sip:", 4); contact->len += 4; p += 4; }