Browse Source

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);
>       |
Victor Seva 3 năm trước cách đây
mục cha
commit
510013c67d
2 tập tin đã thay đổi với 9 bổ sung6 xóa
  1. 7 4
      src/core/cfg.y
  2. 2 2
      src/core/socket_info.c

+ 7 - 4
src/core/cfg.y

@@ -682,11 +682,12 @@ listen_id:
 				LM_CRIT("cfg. parser: bad ip address.\n");
 				LM_CRIT("cfg. parser: bad ip address.\n");
 				$$=0;
 				$$=0;
 			} else {
 			} else {
-				$$=pkg_malloc(strlen(tmp)+1);
+				i_tmp=strlen(tmp)+1;
+				$$=pkg_malloc(i_tmp);
 				if ($$==0) {
 				if ($$==0) {
 					PKG_MEM_CRITICAL;
 					PKG_MEM_CRITICAL;
 				} else {
 				} else {
-					strncpy($$, tmp, strlen(tmp)+1);
+					strncpy($$, tmp, i_tmp);
 				}
 				}
 			}
 			}
 		}
 		}
@@ -696,7 +697,8 @@ listen_id:
 		if ($$==0) {
 		if ($$==0) {
 				PKG_MEM_CRITICAL;
 				PKG_MEM_CRITICAL;
 		} else {
 		} else {
-				strncpy($$, $1, strlen($1)+1);
+				i_tmp=strlen($1)+1;
+				strncpy($$, $1, i_tmp);
 		}
 		}
 	}
 	}
 	| host_or_if {
 	| host_or_if {
@@ -705,7 +707,8 @@ listen_id:
 			if ($$==0) {
 			if ($$==0) {
 					PKG_MEM_CRITICAL;
 					PKG_MEM_CRITICAL;
 			} else {
 			} else {
-					strncpy($$, $1, strlen($1)+1);
+					i_tmp=strlen($1)+1;
+					strncpy($$, $1, i_tmp);
 			}
 			}
 		}
 		}
 	}
 	}

+ 2 - 2
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;
 		PKG_MEM_ERROR;
 		goto 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);
 	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) &&
 	if (sr_auto_aliases && (address_str->len==name->len) &&
 		(strncasecmp(address_str->s, name->s, address_str->len)==0)){
 		(strncasecmp(address_str->s, name->s, address_str->len)==0)){
 		*flags|=SI_IS_IP;
 		*flags|=SI_IS_IP;