* [PATCH] tipc: use destination length for copy string
@ 2018-10-19 4:08 Guoqing Jiang
2018-10-19 4:31 ` Ying Xue
2018-10-23 2:25 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Guoqing Jiang @ 2018-10-19 4:08 UTC (permalink / raw)
To: jon.maloy, ying.xue, davem; +Cc: netdev, tipc-discussion, Guoqing Jiang
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@suse.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);
--
2.12.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tipc: use destination length for copy string
2018-10-19 4:08 [PATCH] tipc: use destination length for copy string Guoqing Jiang
@ 2018-10-19 4:31 ` Ying Xue
2018-10-23 2:25 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Ying Xue @ 2018-10-19 4:31 UTC (permalink / raw)
To: Guoqing Jiang, jon.maloy, davem; +Cc: netdev, tipc-discussion
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@suse.com>
Acked-by: Ying Xue <ying.xue@windriver.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);
>
>
_______________________________________________
tipc-discussion mailing list
tipc-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tipc-discussion
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tipc: use destination length for copy string
2018-10-19 4:08 [PATCH] tipc: use destination length for copy string Guoqing Jiang
2018-10-19 4:31 ` Ying Xue
@ 2018-10-23 2:25 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2018-10-23 2:25 UTC (permalink / raw)
To: gqjiang; +Cc: jon.maloy, ying.xue, netdev, tipc-discussion
From: Guoqing Jiang <gqjiang@suse.com>
Date: Fri, 19 Oct 2018 12:08:22 +0800
> 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@suse.com>
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-10-23 10:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-19 4:08 [PATCH] tipc: use destination length for copy string Guoqing Jiang
2018-10-19 4:31 ` Ying Xue
2018-10-23 2:25 ` David Miller
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).