From patchwork Fri Jun 7 13:05:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10981651 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 4988C14E5 for ; Fri, 7 Jun 2019 13:07:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37DFC289D1 for ; Fri, 7 Jun 2019 13:07:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2921728BAB; Fri, 7 Jun 2019 13:07:55 +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 BFB5228947 for ; Fri, 7 Jun 2019 13:07:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A98153091DD1; Fri, 7 Jun 2019 13:07:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3593E8231E; Fri, 7 Jun 2019 13:07:17 +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 D9066206D3; Fri, 7 Jun 2019 13:06:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x57D6lZZ000343 for ; Fri, 7 Jun 2019 09:06:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 02BE47FE8D; Fri, 7 Jun 2019 13:06:47 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B0F0E7FE8C; Fri, 7 Jun 2019 13:06:44 +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 81BEC30001D8; Fri, 7 Jun 2019 13:06:14 +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:07 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Fri, 7 Jun 2019 15:05:24 +0200 Message-Id: <20190607130552.13203-3-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.40]); Fri, 07 Jun 2019 13:06:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); 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.298 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_NONE) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 02/30] libmultipath: fix gcc -Wstringop-truncation warning in set_value() 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 07 Jun 2019 13:07:53 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Fixes the following warning: In function ‘strncat’, inlined from ‘set_value’ at parser.c:382:3: /usr/include/bits/string_fortified.h:136:10: warning: ‘__builtin_strncat’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 136 | return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ parser.c: In function ‘set_value’: parser.c:382:3: note: length computed here 382 | strncat(alloc, str, strlen(str)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gcc's stringop checker expects that the size argument of strncat() is derived from the destination, not source, side. See https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/ Fix typo in error message along the way. Signed-off-by: Martin Wilck --- libmultipath/parser.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/libmultipath/parser.c b/libmultipath/parser.c index 92ef7cf5..e00c5fff 100644 --- a/libmultipath/parser.c +++ b/libmultipath/parser.c @@ -345,17 +345,13 @@ set_value(vector strvec) if (alloc) memcpy(alloc, str, size); else - condlog(0, "can't allocate memeory for option '%s'", - (char *)VECTOR_SLOT(strvec, 0)); + goto oom; return alloc; } /* Even empty quotes counts as a value (An empty string) */ alloc = (char *) MALLOC(sizeof (char)); - if (!alloc) { - condlog(0, "can't allocate memeory for option '%s'", - (char *)VECTOR_SLOT(strvec, 0)); - return NULL; - } + if (!alloc) + goto oom; for (i = 2; i < VECTOR_SIZE(strvec); i++) { str = VECTOR_SLOT(strvec, i); if (!str) { @@ -373,15 +369,17 @@ set_value(vector strvec) alloc = REALLOC(alloc, sizeof (char) * len); if (!alloc) { FREE(tmp); - condlog(0, "can't allocate memeory for option '%s'", - (char *)VECTOR_SLOT(strvec, 0)); - return NULL; + goto oom; } if (*alloc != '\0') strncat(alloc, " ", 1); - strncat(alloc, str, strlen(str)); + strncat(alloc, str, len - strlen(alloc) - 1); } return alloc; +oom: + condlog(0, "can't allocate memory for option '%s'", + (char *)VECTOR_SLOT(strvec, 0)); + return NULL; } /* non-recursive configuration stream handler */