From patchwork Fri Jun 7 13:05:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10981659 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF09B14E5 for ; Fri, 7 Jun 2019 13:08:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD1A5286BC for ; Fri, 7 Jun 2019 13:08:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A148E288F8; Fri, 7 Jun 2019 13:08:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0DB5A286BC for ; Fri, 7 Jun 2019 13:08:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7052230C31B9; Fri, 7 Jun 2019 13:08:44 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F2817D562; Fri, 7 Jun 2019 13:08:43 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1B7E518433A5; Fri, 7 Jun 2019 13:08:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x57D6kNq000337 for ; Fri, 7 Jun 2019 09:06:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE50682F56; Fri, 7 Jun 2019 13:06:46 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BCA9C82268; Fri, 7 Jun 2019 13:06:41 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9441F81F0E; Fri, 7 Jun 2019 13:06:23 +0000 (UTC) Received: from apollon.suse.de.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Fri, 07 Jun 2019 07:06:11 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:27 +0200 Message-Id: <20190607130552.13203-6-mwilck@suse.com> In-Reply-To: <20190607130552.13203-1-mwilck@suse.com> References: <20190607130552.13203-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 07 Jun 2019 13:06:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 07 Jun 2019 13:06:28 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.3 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 05/30] multipath-tools: fix more gcc 9 -Wstringop-truncation warnings X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 07 Jun 2019 13:08:45 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP More often than not, this means replacing strncpy() by strlcpy(). Signed-off-by: Martin Wilck --- libmpathpersist/mpath_persist.c | 8 ++++---- libmultipath/configure.c | 7 ++++--- libmultipath/discovery.c | 12 ++++++------ libmultipath/dmparser.c | 20 +++++++++----------- libmultipath/util.c | 2 +- libmultipath/uxsock.c | 2 +- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/libmpathpersist/mpath_persist.c b/libmpathpersist/mpath_persist.c index 599c5e9e..4abcaed5 100644 --- a/libmpathpersist/mpath_persist.c +++ b/libmpathpersist/mpath_persist.c @@ -497,8 +497,8 @@ int mpath_prout_reg(struct multipath *mpp,int rq_servact, int rq_scope, if (k < count) continue; } - strncpy(thread[count].param.dev, pp->dev, - FILE_NAME_SIZE - 1); + strlcpy(thread[count].param.dev, pp->dev, + FILE_NAME_SIZE); if (count && (thread[count].param.paramp->sa_flags & MPATH_F_SPEC_I_PT_MASK)){ /* @@ -686,8 +686,8 @@ int mpath_prout_rel(struct multipath *mpp,int rq_servact, int rq_scope, continue; } - strncpy(thread[count].param.dev, pp->dev, - FILE_NAME_SIZE - 1); + strlcpy(thread[count].param.dev, pp->dev, + FILE_NAME_SIZE); condlog (3, "%s: sending pr out command to %s", mpp->wwid, pp->dev); rc = pthread_create (&thread[count].id, &attr, mpath_prout_pthread_fn, (void *) (&thread[count].param)); diff --git a/libmultipath/configure.c b/libmultipath/configure.c index af4d78de..dfee7d24 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -73,7 +73,7 @@ int group_by_host_adapter(struct pathgroup *pgp, vector adapters) goto out; agp->pgp = pgp; - strncpy(agp->adapter_name, adapter_name1, SLOT_NAME_SIZE - 1); + strlcpy(agp->adapter_name, adapter_name1, SLOT_NAME_SIZE); store_adaptergroup(adapters, agp); /* create a new host port group @@ -667,7 +667,7 @@ select_action (struct multipath * mpp, vector curmp, int force_reload) if (!cmpp) { condlog(2, "%s: remove (wwid changed)", mpp->alias); dm_flush_map(mpp->alias); - strncpy(cmpp_by_name->wwid, mpp->wwid, WWID_SIZE - 1); + strlcpy(cmpp_by_name->wwid, mpp->wwid, WWID_SIZE); drop_multipath(curmp, cmpp_by_name->wwid, KEEP_PATHS); mpp->action = ACT_CREATE; condlog(3, "%s: set ACT_CREATE (map wwid change)", @@ -1451,7 +1451,8 @@ int get_refwwid(enum mpath_cmds cmd, char *dev, enum devtypes dev_type, conf = get_multipath_config(); pthread_cleanup_push(put_multipath_config, conf); - if (((dm_get_uuid(dev, tmpwwid)) == 0) && (strlen(tmpwwid))) { + if (((dm_get_uuid(dev, tmpwwid, WWID_SIZE)) == 0) + && (strlen(tmpwwid))) { refwwid = tmpwwid; goto check; } diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 51ca2306..407e64a0 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -297,8 +297,8 @@ sysfs_get_timeout(const struct path *pp, unsigned int *timeout) return 1; } -int -sysfs_get_tgt_nodename (struct path *pp, char * node) +static int +sysfs_get_tgt_nodename(struct path *pp, char *node) { const char *tgtname, *value; struct udev_device *parent, *tgtdev; @@ -322,7 +322,7 @@ sysfs_get_tgt_nodename (struct path *pp, char * node) if (tgtid >= 0) { pp->sg_id.proto_id = SCSI_PROTOCOL_SAS; pp->sg_id.transport_id = tgtid; - strncpy(node, value, NODE_NAME_SIZE); + strlcpy(node, value, NODE_NAME_SIZE); return 0; } } @@ -334,7 +334,7 @@ sysfs_get_tgt_nodename (struct path *pp, char * node) if (value && !strcmp(value, "usb")) { pp->sg_id.proto_id = SCSI_PROTOCOL_UNSPEC; tgtname = udev_device_get_sysname(tgtdev); - strncpy(node, tgtname, strlen(tgtname)); + strlcpy(node, tgtname, NODE_NAME_SIZE); condlog(3, "%s: skip USB device %s", pp->dev, node); return 1; } @@ -361,7 +361,7 @@ sysfs_get_tgt_nodename (struct path *pp, char * node) if (value) { pp->sg_id.proto_id = SCSI_PROTOCOL_FCP; pp->sg_id.transport_id = tgtid; - strncpy(node, value, NODE_NAME_SIZE); + strlcpy(node, value, NODE_NAME_SIZE); udev_device_unref(tgtdev); return 0; } else @@ -390,7 +390,7 @@ sysfs_get_tgt_nodename (struct path *pp, char * node) if (value) { pp->sg_id.proto_id = SCSI_PROTOCOL_ISCSI; pp->sg_id.transport_id = tgtid; - strncpy(node, value, NODE_NAME_SIZE); + strlcpy(node, value, NODE_NAME_SIZE); udev_device_unref(tgtdev); return 0; } diff --git a/libmultipath/dmparser.c b/libmultipath/dmparser.c index a8b0b71a..b856a07f 100644 --- a/libmultipath/dmparser.c +++ b/libmultipath/dmparser.c @@ -308,11 +308,11 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, if (!pp) goto out1; - strncpy(pp->dev_t, word, BLK_DEV_SIZE - 1); - strncpy(pp->dev, devname, FILE_NAME_SIZE - 1); + strlcpy(pp->dev_t, word, BLK_DEV_SIZE); + strlcpy(pp->dev, devname, FILE_NAME_SIZE); if (strlen(mpp->wwid)) { - strncpy(pp->wwid, mpp->wwid, - WWID_SIZE - 1); + strlcpy(pp->wwid, mpp->wwid, + WWID_SIZE); } /* Only call this in multipath client mode */ if (!is_daemon && store_path(pathvec, pp)) @@ -320,8 +320,8 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, } else { if (!strlen(pp->wwid) && strlen(mpp->wwid)) - strncpy(pp->wwid, mpp->wwid, - WWID_SIZE - 1); + strlcpy(pp->wwid, mpp->wwid, + WWID_SIZE); } FREE(word); @@ -333,23 +333,21 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, * in the get_dm_mpvec() code path */ if (!strlen(mpp->wwid)) - strncpy(mpp->wwid, pp->wwid, - WWID_SIZE - 1); + strlcpy(mpp->wwid, pp->wwid, WWID_SIZE); /* * Update wwid for paths which may not have been * active at the time the getuid callout was run */ else if (!strlen(pp->wwid)) - strncpy(pp->wwid, mpp->wwid, - WWID_SIZE - 1); + strlcpy(pp->wwid, mpp->wwid, WWID_SIZE); /* * Do not allow in-use patch to change wwid */ else if (strcmp(pp->wwid, mpp->wwid) != 0) { condlog(0, "%s: path wwid appears to have changed. Using map wwid.\n", pp->dev_t); - strncpy(pp->wwid, mpp->wwid, WWID_SIZE); + strlcpy(pp->wwid, mpp->wwid, WWID_SIZE); } pgp->id ^= (long)pp; diff --git a/libmultipath/util.c b/libmultipath/util.c index 5b838d51..8a4be787 100644 --- a/libmultipath/util.c +++ b/libmultipath/util.c @@ -188,7 +188,7 @@ int devt2devname(char *devname, int devname_len, char *devt) return 1; } p++; - strncpy(devname, p, devname_len); + strlcpy(devname, p, devname_len); return 0; } } diff --git a/libmultipath/uxsock.c b/libmultipath/uxsock.c index 7e5a1449..1ec4549b 100644 --- a/libmultipath/uxsock.c +++ b/libmultipath/uxsock.c @@ -67,7 +67,7 @@ int ux_socket_listen(const char *name) addr.sun_family = AF_LOCAL; addr.sun_path[0] = '\0'; len = strlen(name) + 1 + sizeof(sa_family_t); - strncpy(&addr.sun_path[1], name, len); + strncpy(&addr.sun_path[1], name, sizeof(addr.sun_path) - 1); if (bind(fd, (struct sockaddr *)&addr, len) == -1) { condlog(3, "Couldn't bind to ux_socket, error %d", errno);