Module: kamailio Branch: master Commit: 510013c67df999e5637b6f289c02b3387691ce89 URL: https://github.com/kamailio/kamailio/commit/510013c67df999e5637b6f289c02b338...
Author: Victor Seva linuxmaniac@torreviejawireless.org Committer: Victor Seva linuxmaniac@torreviejawireless.org Date: 2022-07-01T15:35:20+02:00
core: fix build warning
In file included from /usr/include/string.h:519, from core/socket_info.c:34: In function 'strncpy', inlined from 'fix_hostname' at core/socket_info.c:1741:2: Warning: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation] 95 | return __builtin___strncpy_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96 | __glibc_objsize (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~ core/socket_info.c: In function 'fix_hostname': core/socket_info.c:1741:38: note: length computed here 1741 | strncpy(address_str->s, tmp, strlen(tmp)+1); | ^~~~~~~~~~~ In file included from /usr/include/string.h:519, from core/socket_info.c:34: In function 'strncpy', inlined from 'build_iface_list' at core/socket_info.c:1554:5: Warning: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: '__builtin_strncpy' output may be truncated copying 63 bytes from a string of length 63 [-Wstringop-truncation] 95 | return __builtin___strncpy_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96 | __glibc_objsize (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/string.h:519, from core/cfg.y:40: In function 'strncpy', inlined from 'yyparse' at core/cfg.y:708:6: Warning: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation] 95 | return __builtin___strncpy_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96 | __glibc_objsize (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~ core/cfg.tab.c: In function 'yyparse': core/cfg.y:708:84: note: length computed here 708 | strncpy($$, $1, strlen($1)+1); | ^ In file included from /usr/include/string.h:519, from core/cfg.y:40: In function 'strncpy', inlined from 'yyparse' at core/cfg.y:699:5: Warning: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation] 95 | return __builtin___strncpy_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96 | __glibc_objsize (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~ core/cfg.tab.c: In function 'yyparse': core/cfg.y:699:76: note: length computed here 699 | strncpy($$, $1, strlen($1)+1); | ^ In file included from /usr/include/string.h:519, from core/cfg.y:40: In function 'strncpy', inlined from 'yyparse' at core/cfg.y:689:6: Warning: /usr/include/x86_64-linux-gnu/bits/string_fortified.h:95:10: warning: '__builtin_strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation] 95 | return __builtin___strncpy_chk (__dest, __src, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 96 | __glibc_objsize (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~ core/cfg.tab.c: In function 'yyparse': core/cfg.y:689:70: note: length computed here 689 | strncpy($$, tmp, strlen(tmp)+1); |
---
Modified: src/core/cfg.y Modified: src/core/socket_info.c
---
Diff: https://github.com/kamailio/kamailio/commit/510013c67df999e5637b6f289c02b338... Patch: https://github.com/kamailio/kamailio/commit/510013c67df999e5637b6f289c02b338...
---
diff --git a/src/core/cfg.y b/src/core/cfg.y index dd93f5f98b..19ba698f27 100644 --- a/src/core/cfg.y +++ b/src/core/cfg.y @@ -682,11 +682,12 @@ listen_id: LM_CRIT("cfg. parser: bad ip address.\n"); $$=0; } else { - $$=pkg_malloc(strlen(tmp)+1); + i_tmp=strlen(tmp)+1; + $$=pkg_malloc(i_tmp); if ($$==0) { PKG_MEM_CRITICAL; } else { - strncpy($$, tmp, strlen(tmp)+1); + strncpy($$, tmp, i_tmp); } } } @@ -696,7 +697,8 @@ listen_id: if ($$==0) { PKG_MEM_CRITICAL; } else { - strncpy($$, $1, strlen($1)+1); + i_tmp=strlen($1)+1; + strncpy($$, $1, i_tmp); } } | host_or_if { @@ -705,7 +707,8 @@ listen_id: if ($$==0) { PKG_MEM_CRITICAL; } else { - strncpy($$, $1, strlen($1)+1); + i_tmp=strlen($1)+1; + strncpy($$, $1, i_tmp); } } } diff --git a/src/core/socket_info.c b/src/core/socket_info.c index e4e83d86b3..8c91e873fe 100644 --- a/src/core/socket_info.c +++ b/src/core/socket_info.c @@ -1738,9 +1738,9 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str, PKG_MEM_ERROR; goto error; } - strncpy(address_str->s, tmp, strlen(tmp)+1); - /* set is_ip (1 if name is an ip address, 0 otherwise) */ address_str->len=strlen(tmp); + strncpy(address_str->s, tmp, address_str->len+1); + /* set is_ip (1 if name is an ip address, 0 otherwise) */ if (sr_auto_aliases && (address_str->len==name->len) && (strncasecmp(address_str->s, name->s, address_str->len)==0)){ *flags|=SI_IS_IP;