From patchwork Tue Jun 13 19:28:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 9784503 X-Patchwork-Delegate: snitzer@redhat.com 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 EB24D602C9 for ; Tue, 13 Jun 2017 19:29:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF16E28469 for ; Tue, 13 Jun 2017 19:29:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3D66286E0; Tue, 13 Jun 2017 19:29:06 +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=-6.9 required=2.0 tests=BAYES_00,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 526F728469 for ; Tue, 13 Jun 2017 19:29:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A09F12016; Tue, 13 Jun 2017 19:29:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0A09F12016 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0A09F12016 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 034BAA395A; Tue, 13 Jun 2017 19:29:03 +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 E0E4C1841C50; Tue, 13 Jun 2017 19:29:00 +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 v5DJSwJM002044 for ; Tue, 13 Jun 2017 15:28:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9E6D28A8B5; Tue, 13 Jun 2017 19:28:58 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 97D341821E for ; Tue, 13 Jun 2017 19:28:56 +0000 (UTC) Received: from prv3-mh.provo.novell.com (victor.provo.novell.com [137.65.250.26]) (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 61AEDD598D for ; Tue, 13 Jun 2017 19:28:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 61AEDD598D Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mwilck@suse.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 61AEDD598D Received: from apollon.mittagstun.de (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (TLS encrypted); Tue, 13 Jun 2017 13:28:47 -0600 Message-ID: <1497382123.4654.48.camel@suse.com> From: Martin Wilck To: Bart Van Assche , Christophe Varoqui Date: Tue, 13 Jun 2017 21:28:43 +0200 In-Reply-To: <20170613163339.23005-5-bart.vanassche@sandisk.com> References: <20170613163339.23005-1-bart.vanassche@sandisk.com> <20170613163339.23005-5-bart.vanassche@sandisk.com> Mime-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 13 Jun 2017 19:28:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 13 Jun 2017 19:28:55 +0000 (UTC) for IP:'137.65.250.26' DOMAIN:'victor.provo.novell.com' HELO:'prv3-mh.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -1.501 (BAYES_50, RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.26 victor.provo.novell.com 137.65.250.26 victor.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: Re: [dm-devel] [PATCH 4/4] multipath: Fix a potential buffer overflow 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 13 Jun 2017 19:29:05 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Hi Bart, On Tue, 2017-06-13 at 09:33 -0700, Bart Van Assche wrote: > Avoid that gcc 7 reports the following warning: > > cli_handlers.c:1340:18: warning: '%d' directive writing between 1 and > 3 bytes into a region of size 2 [-Wformat-overflow=] > sprintf(*reply,"%d",mpp->prflag); > > Signed-off-by: Bart Van Assche > --- > multipathd/cli_handlers.c | 14 ++++++-------- > 1 file changed, 6 insertions(+), 8 deletions(-) > > diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c > index 04c73866..460fea1f 100644 > --- a/multipathd/cli_handlers.c > +++ b/multipathd/cli_handlers.c > @@ -1,6 +1,9 @@ > /* > * Copyright (c) 2005 Christophe Varoqui > */ > + > +#define _GNU_SOURCE > + > #include "checkers.h" > #include "memory.h" > #include "vector.h" > @@ -1332,14 +1335,9 @@ cli_getprstatus (void * v, char ** reply, int > * len, void * data) > > condlog(3, "%s: prflag = %u", param, (unsigned int)mpp- > >prflag); > > - *reply =(char *)malloc(2); > - *len = 2; > - memset(*reply,0,2); > - > - > - sprintf(*reply,"%d",mpp->prflag); > - (*reply)[1]='\0'; > - > + *len = asprintf(reply, "%d", mpp->prflag); > + if (*len < 0) > + return 1; > > condlog(3, "%s: reply = %s", param, *reply); > how about this simpler patch, as prflag is actually a boolean? diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c index 04c73866..c31ebd34 100644 --- a/multipathd/cli_handlers.c +++ b/multipathd/cli_handlers.c @@ -1337,7 +1337,7 @@ cli_getprstatus (void * v, char ** reply, int * len, void * data) memset(*reply,0,2); - sprintf(*reply,"%d",mpp->prflag); + sprintf(*reply, "%d", !!mpp->prflag); (*reply)[1]='\0';