From patchwork Tue Jun 5 15:30:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Steve Dickson X-Patchwork-Id: 10448497 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C665F60284 for ; Tue, 5 Jun 2018 15:32:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B71E029F1E for ; Tue, 5 Jun 2018 15:32:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B338729A87; Tue, 5 Jun 2018 15:32:25 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E698D29A81 for ; Tue, 5 Jun 2018 15:30:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751824AbeFEPag (ORCPT ); Tue, 5 Jun 2018 11:30:36 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33708 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751599AbeFEPag (ORCPT ); Tue, 5 Jun 2018 11:30:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E8484818B13E for ; Tue, 5 Jun 2018 15:30:35 +0000 (UTC) Received: from steved.boston.devel.redhat.com (steved.boston.devel.redhat.com [10.19.60.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id C04D010FFE73 for ; Tue, 5 Jun 2018 15:30:35 +0000 (UTC) From: Steve Dickson To: Linux NFS Mailing list Subject: [PATCH 1/2] Remove a number of stringop-truncation warnings Date: Tue, 5 Jun 2018 11:30:33 -0400 Message-Id: <20180605153034.49074-1-steved@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 05 Jun 2018 15:30:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 05 Jun 2018 15:30:35 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'steved@redhat.com' RCPT:'' Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP client.c:486:3: warning: ‘strncpy’ destination unchanged after copying no bytes [-Wstringop-truncation] file.c:99:2: warning: ‘strncpy’ specified bound 4096 equals destination size [-Wstringop-truncation] v4root.c:95:2: warning: ‘strncpy’ specified bound 1025 equals destination size [-Wstringop-truncation] sm-notify.c:572:3: warning: ‘strncpy’ specified bound 1025 equals destination size [-Wstringop-truncation] nfs4mount.c:221:3: warning: ‘strncpy’ specified bound 1024 equals destination size [-Wstringop-truncation] nfsmount.c:831:2: warning: ‘strncpy’ specified bound 256 equals destination size [-Wstringop-truncation] Signed-off-by: Steve Dickson --- support/export/client.c | 5 +++-- support/misc/file.c | 2 +- utils/mount/nfs4mount.c | 2 +- utils/mount/nfsmount.c | 2 +- utils/mountd/v4root.c | 2 +- utils/statd/sm-notify.c | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/support/export/client.c b/support/export/client.c index 2346f99..baf59c8 100644 --- a/support/export/client.c +++ b/support/export/client.c @@ -482,8 +482,9 @@ add_name(char *old, const char *add) else cp = cp + strlen(cp); } - if (old) { - strncpy(new, old, cp-old); + len = cp-old; + if (old && len > 0) { + strncpy(new, old, len); new[cp-old] = 0; } else { new[0] = 0; diff --git a/support/misc/file.c b/support/misc/file.c index 63597df..4065376 100644 --- a/support/misc/file.c +++ b/support/misc/file.c @@ -96,7 +96,7 @@ generic_setup_basedir(const char *progname, const char *parentdir, char *base, } /* Ensure we have a clean directory pathname */ - strncpy(buf, parentdir, sizeof(buf)); + strncpy(buf, parentdir, sizeof(buf)-1); path = dirname(buf); if (*path == '.') { (void)fprintf(stderr, "%s: Unusable directory %s", diff --git a/utils/mount/nfs4mount.c b/utils/mount/nfs4mount.c index 89629ed..3e4f1e2 100644 --- a/utils/mount/nfs4mount.c +++ b/utils/mount/nfs4mount.c @@ -218,7 +218,7 @@ int nfs4mount(const char *spec, const char *node, int flags, goto fail; } if (running_bg) - strncpy(new_opts, old_opts, sizeof(new_opts)); + strncpy(new_opts, old_opts, sizeof(new_opts)-1); else snprintf(new_opts, sizeof(new_opts), "%s%saddr=%s", old_opts, *old_opts ? "," : "", s); diff --git a/utils/mount/nfsmount.c b/utils/mount/nfsmount.c index ae4a3da..952a755 100644 --- a/utils/mount/nfsmount.c +++ b/utils/mount/nfsmount.c @@ -828,7 +828,7 @@ noauth_flavors: data.fd = fsock; memcpy((char *) &data.addr, (char *) nfs_saddr, sizeof(data.addr)); - strncpy(data.hostname, hostname, sizeof(data.hostname)); + strncpy(data.hostname, hostname, sizeof(data.hostname)-1); out_ok: /* Ensure we have enough padding for the following strcat()s */ diff --git a/utils/mountd/v4root.c b/utils/mountd/v4root.c index f978f4c..d735dbf 100644 --- a/utils/mountd/v4root.c +++ b/utils/mountd/v4root.c @@ -92,7 +92,7 @@ v4root_create(char *path, nfs_export *export) dupexportent(&eep, &pseudo_root.m_export); eep.e_hostname = curexp->e_hostname; - strncpy(eep.e_path, path, sizeof(eep.e_path)); + strncpy(eep.e_path, path, sizeof(eep.e_path)-1); if (strcmp(path, "/") != 0) eep.e_flags &= ~NFSEXP_FSID; set_pseudofs_security(&eep, curexp->e_flags); diff --git a/utils/statd/sm-notify.c b/utils/statd/sm-notify.c index 6d19ec1..7a48473 100644 --- a/utils/statd/sm-notify.c +++ b/utils/statd/sm-notify.c @@ -569,7 +569,7 @@ usage: fprintf(stderr, if (name == NULL) exit(1); - strncpy(nsm_hostname, name, sizeof(nsm_hostname)); + strncpy(nsm_hostname, name, sizeof(nsm_hostname)-1); free(name); }