[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b2dac0b9-f3f5-38ac-5b3c-70acf5052311@windriver.com>
Date:   Fri, 19 Oct 2018 12:31:54 +0800
From:   Ying Xue <ying.xue@...driver.com>
To:     Guoqing Jiang <gqjiang@...e.com>, <jon.maloy@...csson.com>,
        <davem@...emloft.net>
CC:     <netdev@...r.kernel.org>, <tipc-discussion@...ts.sourceforge.net>
Subject: Re: [PATCH] tipc: use destination length for copy string
On 10/19/2018 12:08 PM, Guoqing Jiang wrote:
> Got below warning with gcc 8.2 compiler.
> 
> net/tipc/topsrv.c: In function ‘tipc_topsrv_start’:
> net/tipc/topsrv.c:660:2: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
>   strncpy(srv->name, name, strlen(name) + 1);
>   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> net/tipc/topsrv.c:660:27: note: length computed here
>   strncpy(srv->name, name, strlen(name) + 1);
>                            ^~~~~~~~~~~~
> So change it to correct length and use strscpy.
> 
> Signed-off-by: Guoqing Jiang <gqjiang@...e.com>
Acked-by: Ying Xue <ying.xue@...driver.com>
> ---
>  net/tipc/topsrv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/tipc/topsrv.c b/net/tipc/topsrv.c
> index 2627b5d812e9..b84c0059214f 100644
> --- a/net/tipc/topsrv.c
> +++ b/net/tipc/topsrv.c
> @@ -657,7 +657,7 @@ int tipc_topsrv_start(struct net *net)
>  	srv->max_rcvbuf_size = sizeof(struct tipc_subscr);
>  	INIT_WORK(&srv->awork, tipc_topsrv_accept);
>  
> -	strncpy(srv->name, name, strlen(name) + 1);
> +	strscpy(srv->name, name, sizeof(srv->name));
>  	tn->topsrv = srv;
>  	atomic_set(&tn->subscription_count, 0);
>  
> 
Powered by blists - more mailing lists
 
