{"id":808819,"url":"http://patchwork.ozlabs.org/api/1.0/patches/808819/?format=json","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/1.0/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20170901165256.21459-3-phil@nwl.cc>","date":"2017-09-01T16:52:52","name":"[iproute,2/6] Convert the obvious cases to strlcpy()","commit_ref":null,"pull_url":null,"state":"accepted","archived":true,"hash":"5b9e17a51fb402d8ea035ebcfe5d4226d3f69f68","submitter":{"id":4285,"url":"http://patchwork.ozlabs.org/api/1.0/people/4285/?format=json","name":"Phil Sutter","email":"phil@nwl.cc"},"delegate":{"id":389,"url":"http://patchwork.ozlabs.org/api/1.0/users/389/?format=json","username":"shemminger","first_name":"stephen","last_name":"hemminger","email":"shemminger@vyatta.com"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/20170901165256.21459-3-phil@nwl.cc/mbox/","series":[{"id":1076,"url":"http://patchwork.ozlabs.org/api/1.0/series/1076/?format=json","date":"2017-09-01T16:52:50","name":"strlcpy() and strlcat() for iproute2","version":1,"mbox":"http://patchwork.ozlabs.org/series/1076/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/808819/checks/","tags":{},"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xkQL23LCzz9t2x\n\tfor <patchwork-incoming@ozlabs.org>;\n\tSat,  2 Sep 2017 02:53:30 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752182AbdIAQx2 (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tFri, 1 Sep 2017 12:53:28 -0400","from orbyte.nwl.cc ([151.80.46.58]:47059 \"EHLO mail.nwl.cc\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1752148AbdIAQx1 (ORCPT <rfc822;netdev@vger.kernel.org>);\n\tFri, 1 Sep 2017 12:53:27 -0400","from mail.nwl.cc (orbyte.nwl.cc [127.0.0.1])\n\tby mail.nwl.cc (Postfix) with ESMTP id BDF4D65A5E;\n\tFri,  1 Sep 2017 18:53:26 +0200 (CEST)","from xsao (localhost [IPv6:::1])\n\tby mail.nwl.cc (Postfix) with ESMTP id A3025644CF;\n\tFri,  1 Sep 2017 18:53:26 +0200 (CEST)"],"From":"Phil Sutter <phil@nwl.cc>","To":"Stephen Hemminger <stephen@networkplumber.org>","Cc":"netdev@vger.kernel.org","Subject":"[iproute PATCH 2/6] Convert the obvious cases to strlcpy()","Date":"Fri,  1 Sep 2017 18:52:52 +0200","Message-Id":"<20170901165256.21459-3-phil@nwl.cc>","X-Mailer":"git-send-email 2.13.1","In-Reply-To":"<20170901165256.21459-1-phil@nwl.cc>","References":"<20170901165256.21459-1-phil@nwl.cc>","X-Virus-Scanned":"ClamAV using ClamSMTP","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"This converts the typical idiom of manually terminating the buffer after\na call to strncpy().\n\nSigned-off-by: Phil Sutter <phil@nwl.cc>\n---\n ip/ipnetns.c          | 3 +--\n ip/iproute_lwtunnel.c | 3 +--\n ip/ipvrf.c            | 3 +--\n lib/bpf.c             | 3 +--\n lib/fs.c              | 3 +--\n lib/inet_proto.c      | 3 +--\n misc/ss.c             | 3 +--\n tc/em_ipset.c         | 3 +--\n 8 files changed, 8 insertions(+), 16 deletions(-)","diff":"diff --git a/ip/ipnetns.c b/ip/ipnetns.c\nindex 9ee1fe6a51f9c..afb4978a5be7d 100644\n--- a/ip/ipnetns.c\n+++ b/ip/ipnetns.c\n@@ -518,8 +518,7 @@ int netns_identify_pid(const char *pidstr, char *name, int len)\n \n \t\tif ((st.st_dev == netst.st_dev) &&\n \t\t    (st.st_ino == netst.st_ino)) {\n-\t\t\tstrncpy(name, entry->d_name, len - 1);\n-\t\t\tname[len - 1] = '\\0';\n+\t\t\tstrlcpy(name, entry->d_name, len);\n \t\t}\n \t}\n \tclosedir(dir);\ndiff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c\nindex 1a3dc4d4c0ed9..4c2d3b07e3b5c 100644\n--- a/ip/iproute_lwtunnel.c\n+++ b/ip/iproute_lwtunnel.c\n@@ -325,8 +325,7 @@ static int parse_encap_seg6(struct rtattr *rta, size_t len, int *argcp,\n \t\t\t\tinvarg(\"\\\"segs\\\" provided before \\\"mode\\\"\\n\",\n \t\t\t\t       *argv);\n \n-\t\t\tstrncpy(segbuf, *argv, 1024);\n-\t\t\tsegbuf[1023] = 0;\n+\t\t\tstrlcpy(segbuf, *argv, 1024);\n \t\t} else if (strcmp(*argv, \"hmac\") == 0) {\n \t\t\tNEXT_ARG();\n \t\t\tif (hmac_ok++)\ndiff --git a/ip/ipvrf.c b/ip/ipvrf.c\nindex e6fad32abd956..b74c501e0970c 100644\n--- a/ip/ipvrf.c\n+++ b/ip/ipvrf.c\n@@ -336,8 +336,7 @@ static int vrf_path(char *vpath, size_t len)\n \t\tif (vrf)\n \t\t\t*vrf = '\\0';\n \n-\t\tstrncpy(vpath, start, len - 1);\n-\t\tvpath[len - 1] = '\\0';\n+\t\tstrlcpy(vpath, start, len);\n \n \t\t/* if vrf path is just / then return nothing */\n \t\tif (!strcmp(vpath, \"/\"))\ndiff --git a/lib/bpf.c b/lib/bpf.c\nindex 0bd0a95eafe6c..c180934acc7dc 100644\n--- a/lib/bpf.c\n+++ b/lib/bpf.c\n@@ -512,8 +512,7 @@ static const char *bpf_find_mntpt_single(unsigned long magic, char *mnt,\n \n \tret = bpf_valid_mntpt(mntpt, magic);\n \tif (!ret) {\n-\t\tstrncpy(mnt, mntpt, len - 1);\n-\t\tmnt[len - 1] = 0;\n+\t\tstrlcpy(mnt, mntpt, len);\n \t\treturn mnt;\n \t}\n \ndiff --git a/lib/fs.c b/lib/fs.c\nindex ebe05cd44e11b..86efd4ed2ed80 100644\n--- a/lib/fs.c\n+++ b/lib/fs.c\n@@ -172,8 +172,7 @@ int get_command_name(const char *pid, char *comm, size_t len)\n \t\tif (nl)\n \t\t\t*nl = '\\0';\n \n-\t\tstrncpy(comm, name, len - 1);\n-\t\tcomm[len - 1] = '\\0';\n+\t\tstrlcpy(comm, name, len);\n \t\tbreak;\n \t}\n \ndiff --git a/lib/inet_proto.c b/lib/inet_proto.c\nindex 53c029039b6d5..bdfd52fdafe5a 100644\n--- a/lib/inet_proto.c\n+++ b/lib/inet_proto.c\n@@ -38,8 +38,7 @@ const char *inet_proto_n2a(int proto, char *buf, int len)\n \t\t\tfree(ncache);\n \t\ticache = proto;\n \t\tncache = strdup(pe->p_name);\n-\t\tstrncpy(buf, pe->p_name, len - 1);\n-\t\tbuf[len - 1] = '\\0';\n+\t\tstrlcpy(buf, pe->p_name, len);\n \t\treturn buf;\n \t}\n \tsnprintf(buf, len, \"ipproto-%d\", proto);\ndiff --git a/misc/ss.c b/misc/ss.c\nindex 2c9e80e696595..dd8dfaa4e70db 100644\n--- a/misc/ss.c\n+++ b/misc/ss.c\n@@ -425,8 +425,7 @@ static void user_ent_hash_build(void)\n \n \tuser_ent_hash_build_init = 1;\n \n-\tstrncpy(name, root, sizeof(name)-1);\n-\tname[sizeof(name)-1] = 0;\n+\tstrlcpy(name, root, sizeof(name));\n \n \tif (strlen(name) == 0 || name[strlen(name)-1] != '/')\n \t\tstrcat(name, \"/\");\ndiff --git a/tc/em_ipset.c b/tc/em_ipset.c\nindex b59756515d239..48b287f5ba3b2 100644\n--- a/tc/em_ipset.c\n+++ b/tc/em_ipset.c\n@@ -145,8 +145,7 @@ get_set_byname(const char *setname, struct xt_set_info *info)\n \tint res;\n \n \treq.op = IP_SET_OP_GET_BYNAME;\n-\tstrncpy(req.set.name, setname, IPSET_MAXNAMELEN);\n-\treq.set.name[IPSET_MAXNAMELEN - 1] = '\\0';\n+\tstrlcpy(req.set.name, setname, IPSET_MAXNAMELEN);\n \tres = do_getsockopt(&req);\n \tif (res != 0)\n \t\treturn -1;\n","prefixes":["iproute","2/6"]}