netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ying Xue <ying.xue@windriver.com>
To: Kang Wenlin <wenlin.kang@windriver.com>,
	jmaloy@redhat.com, davem@davemloft.net, kuba@kernel.org
Cc: netdev@vger.kernel.org, tipc-discussion@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tipc: fix -Wstringop-truncation warnings
Date: Fri, 13 Nov 2020 20:26:13 +0800	[thread overview]
Message-ID: <11e23a8d-766d-fb65-40ce-c7a1fdf00c3c@windriver.com> (raw)
In-Reply-To: <20201112093442.8132-1-wenlin.kang@windriver.com>

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 */
> 

  reply	other threads:[~2020-11-13 12:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-12  9:34 [PATCH] tipc: fix -Wstringop-truncation warnings Kang Wenlin
2020-11-13 12:26 ` Ying Xue [this message]
2020-11-13 22:30 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11e23a8d-766d-fb65-40ce-c7a1fdf00c3c@windriver.com \
    --to=ying.xue@windriver.com \
    --cc=davem@davemloft.net \
    --cc=jmaloy@redhat.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tipc-discussion@lists.sourceforge.net \
    --cc=wenlin.kang@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).