From patchwork Mon Jun 26 18:52:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9810333 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 C4E2A603D7 for ; Mon, 26 Jun 2017 18:59:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C373427813 for ; Mon, 26 Jun 2017 18:59:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7279284FF; Mon, 26 Jun 2017 18:59:20 +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=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (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 465B527813 for ; Mon, 26 Jun 2017 18:59:19 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id ADC6121A00AC1; Mon, 26 Jun 2017 11:57:49 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B72D02095A6D4 for ; Mon, 26 Jun 2017 11:57:48 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP; 26 Jun 2017 11:59:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,397,1493708400"; d="scan'208";a="103851408" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by orsmga002.jf.intel.com with ESMTP; 26 Jun 2017 11:59:17 -0700 Subject: [ndctl PATCH] ndctl: clamp dimm formats From: Dan Williams To: linux-nvdimm@lists.01.org Date: Mon, 26 Jun 2017 11:52:51 -0700 Message-ID: <149850317133.1029.10640606828642185986.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Static analysis warns about unbounded values of 'formats' being passed to calloc. Clamp to the known allowed values. This also updates the max() macro to avoid 'variable shadowed' warnings. Signed-off-by: Dan Williams --- ccan/minmax/minmax.h | 8 ++++---- ndctl/lib/libndctl.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ccan/minmax/minmax.h b/ccan/minmax/minmax.h index d111d1bc3809..54f246cc112d 100644 --- a/ccan/minmax/minmax.h +++ b/ccan/minmax/minmax.h @@ -32,10 +32,10 @@ #define max(a, b) \ ({ \ - typeof(a) _a = (a); \ - typeof(b) _b = (b); \ - MINMAX_ASSERT_COMPATIBLE(typeof(_a), typeof(_b)); \ - _a > _b ? _a : _b; \ + typeof(a) __a = (a); \ + typeof(b) __b = (b); \ + MINMAX_ASSERT_COMPATIBLE(typeof(__a), typeof(__b)); \ + __a > __b ? __a : __b; \ }) #define clamp(v, f, c) (max(min((v), (c)), (f))) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 4acebc05d6db..3b34a10fd429 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -1170,7 +1170,7 @@ static void *add_dimm(void *parent, int id, const char *dimm_base) if (sysfs_read_attr(ctx, path, buf) < 0) formats = 1; else - formats = strtoul(buf, NULL, 0); + formats = clamp(strtoul(buf, NULL, 0), 1UL, 2UL); dimm = calloc(1, sizeof(*dimm) + sizeof(int) * formats); if (!dimm)