Module: kamailio Branch: master Commit: 1062d636fe3a5b79b0ee789e36fd205ea4b87fb3 URL: https://github.com/kamailio/kamailio/commit/1062d636fe3a5b79b0ee789e36fd205e...
Author: Victor Seva linuxmaniac@torreviejawireless.org Committer: Victor Seva linuxmaniac@torreviejawireless.org Date: 2018-09-28T14:42:44+02:00
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); ^~~~~~~~~~~~~~~~~~~~~
---
Modified: src/modules/presence/subscribe.c Modified: src/modules/presence/utils_func.h
---
Diff: https://github.com/kamailio/kamailio/commit/1062d636fe3a5b79b0ee789e36fd205e... Patch: https://github.com/kamailio/kamailio/commit/1062d636fe3a5b79b0ee789e36fd205e...
---
diff --git a/src/modules/presence/subscribe.c b/src/modules/presence/subscribe.c index e3352b1615..e5d8c62d30 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 b68890f21c..bfc8c5654f 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; }