]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.4.175/tipc-use-destination-length-for-copy-string.patch
Linux 4.14.121
[thirdparty/kernel/stable-queue.git] / releases / 4.4.175 / tipc-use-destination-length-for-copy-string.patch
CommitLineData
11d71c9f
GKH
1From 29e270fc32192e7729057963ae7120663856c93e Mon Sep 17 00:00:00 2001
2From: Guoqing Jiang <gqjiang@suse.com>
3Date: Fri, 19 Oct 2018 12:08:22 +0800
4Subject: tipc: use destination length for copy string
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9From: Guoqing Jiang <gqjiang@suse.com>
10
11commit 29e270fc32192e7729057963ae7120663856c93e upstream.
12
13Got below warning with gcc 8.2 compiler.
14
15net/tipc/topsrv.c: In function ‘tipc_topsrv_start’:
16net/tipc/topsrv.c:660:2: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
17 strncpy(srv->name, name, strlen(name) + 1);
18 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19net/tipc/topsrv.c:660:27: note: length computed here
20 strncpy(srv->name, name, strlen(name) + 1);
21 ^~~~~~~~~~~~
22So change it to correct length and use strscpy.
23
24Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
25Acked-by: Ying Xue <ying.xue@windriver.com>
26Signed-off-by: David S. Miller <davem@davemloft.net>
27Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
28
29---
30 net/tipc/subscr.c | 2 +-
31 1 file changed, 1 insertion(+), 1 deletion(-)
32
33--- a/net/tipc/subscr.c
34+++ b/net/tipc/subscr.c
35@@ -337,7 +337,7 @@ int tipc_topsrv_start(struct net *net)
36 topsrv->tipc_conn_new = tipc_subscrb_connect_cb;
37 topsrv->tipc_conn_shutdown = tipc_subscrb_shutdown_cb;
38
39- strncpy(topsrv->name, name, strlen(name) + 1);
40+ strscpy(topsrv->name, name, sizeof(topsrv->name));
41 tn->topsrv = topsrv;
42 atomic_set(&tn->subscription_count, 0);
43