netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tipc: fix -Wstringop-truncation warnings
@ 2020-11-12  9:34 Kang Wenlin
  2020-11-13 12:26 ` Ying Xue
  2020-11-13 22:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Kang Wenlin @ 2020-11-12  9:34 UTC (permalink / raw)
  To: jmaloy, ying.xue, davem, kuba; +Cc: netdev, tipc-discussion, linux-kernel

From: Wenlin Kang <wenlin.kang@windriver.com>

Replace strncpy() with strscpy(), fixes the following warning:

In function 'bearer_name_validate',
    inlined from 'tipc_enable_bearer' at net/tipc/bearer.c:246:7:
net/tipc/bearer.c:141:2: warning: 'strncpy' specified bound 32 equals destination size [-Wstringop-truncation]
  strncpy(name_copy, name, TIPC_MAX_BEARER_NAME);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Wenlin Kang <wenlin.kang@windriver.com>
---
 net/tipc/bearer.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 650414110452..2241d5a38f7b 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -139,10 +139,7 @@ static int bearer_name_validate(const char *name,
 	u32 if_len;
 
 	/* copy bearer name & ensure length is OK */
-	name_copy[TIPC_MAX_BEARER_NAME - 1] = 0;
-	/* need above in case non-Posix strncpy() doesn't pad with nulls */
-	strncpy(name_copy, name, TIPC_MAX_BEARER_NAME);
-	if (name_copy[TIPC_MAX_BEARER_NAME - 1] != 0)
+	if (strscpy(name_copy, name, TIPC_MAX_BEARER_NAME) < 0)
 		return 0;
 
 	/* ensure all component parts of bearer name are present */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tipc: fix -Wstringop-truncation warnings
  2020-11-12  9:34 [PATCH] tipc: fix -Wstringop-truncation warnings Kang Wenlin
@ 2020-11-13 12:26 ` Ying Xue
  2020-11-13 22:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Ying Xue @ 2020-11-13 12:26 UTC (permalink / raw)
  To: Kang Wenlin, jmaloy, davem, kuba; +Cc: netdev, tipc-discussion, linux-kernel

On 11/12/20 5:34 PM, Kang Wenlin wrote:
> From: Wenlin Kang <wenlin.kang@windriver.com>
> 
> Replace strncpy() with strscpy(), fixes the following warning:
> 
> In function 'bearer_name_validate',
>     inlined from 'tipc_enable_bearer' at net/tipc/bearer.c:246:7:
> net/tipc/bearer.c:141:2: warning: 'strncpy' specified bound 32 equals destination size [-Wstringop-truncation]
>   strncpy(name_copy, name, TIPC_MAX_BEARER_NAME);
>   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Signed-off-by: Wenlin Kang <wenlin.kang@windriver.com>

Acked-by: Ying Xue <ying.xue@windriver.com>

> ---
>  net/tipc/bearer.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
> index 650414110452..2241d5a38f7b 100644
> --- a/net/tipc/bearer.c
> +++ b/net/tipc/bearer.c
> @@ -139,10 +139,7 @@ static int bearer_name_validate(const char *name,
>  	u32 if_len;
>  
>  	/* copy bearer name & ensure length is OK */
> -	name_copy[TIPC_MAX_BEARER_NAME - 1] = 0;
> -	/* need above in case non-Posix strncpy() doesn't pad with nulls */
> -	strncpy(name_copy, name, TIPC_MAX_BEARER_NAME);
> -	if (name_copy[TIPC_MAX_BEARER_NAME - 1] != 0)
> +	if (strscpy(name_copy, name, TIPC_MAX_BEARER_NAME) < 0)
>  		return 0;
>  
>  	/* ensure all component parts of bearer name are present */
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tipc: fix -Wstringop-truncation warnings
  2020-11-12  9:34 [PATCH] tipc: fix -Wstringop-truncation warnings Kang Wenlin
  2020-11-13 12:26 ` Ying Xue
@ 2020-11-13 22:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2020-11-13 22:30 UTC (permalink / raw)
  To: Kang Wenlin
  Cc: jmaloy, ying.xue, davem, kuba, netdev, tipc-discussion,
	linux-kernel

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Thu, 12 Nov 2020 17:34:42 +0800 you wrote:
> From: Wenlin Kang <wenlin.kang@windriver.com>
> 
> Replace strncpy() with strscpy(), fixes the following warning:
> 
> In function 'bearer_name_validate',
>     inlined from 'tipc_enable_bearer' at net/tipc/bearer.c:246:7:
> net/tipc/bearer.c:141:2: warning: 'strncpy' specified bound 32 equals destination size [-Wstringop-truncation]
>   strncpy(name_copy, name, TIPC_MAX_BEARER_NAME);
>   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> [...]

Here is the summary with links:
  - tipc: fix -Wstringop-truncation warnings
    https://git.kernel.org/netdev/net-next/c/2f51e5758d61

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-13 22:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-12  9:34 [PATCH] tipc: fix -Wstringop-truncation warnings Kang Wenlin
2020-11-13 12:26 ` Ying Xue
2020-11-13 22:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).