Skip to content

Commit

Permalink
core: fix build warning
Browse files Browse the repository at this point in the history
> 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);
>       |
  • Loading branch information
linuxmaniac committed Jul 1, 2022
1 parent 5c3a008 commit 510013c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/core/cfg.y
Expand Up @@ -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);
}
}
}
Expand All @@ -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 {
Expand All @@ -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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/socket_info.c
Expand Up @@ -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;
Expand Down

0 comments on commit 510013c

Please sign in to comment.