From patchwork Thu Mar 22 18:33:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 10302133 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 B064D600F6 for ; Thu, 22 Mar 2018 18:33:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3565B286B3 for ; Thu, 22 Mar 2018 18:33:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A45D28876; Thu, 22 Mar 2018 18:33:29 +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 39B33286B3 for ; Thu, 22 Mar 2018 18:33:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 90BCF226462FE; Thu, 22 Mar 2018 11:26:55 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: None (no SPF record) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=ross.zwisler@linux.intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 1EDB522551BBD for ; Thu, 22 Mar 2018 11:26:54 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Mar 2018 11:33:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,345,1517904000"; d="scan'208";a="213773372" Received: from theros.lm.intel.com ([10.232.112.164]) by fmsmga006.fm.intel.com with ESMTP; 22 Mar 2018 11:33:25 -0700 From: Ross Zwisler To: Andi Kleen , linux-nvdimm@lists.01.org Subject: [PATCH 1/3] Avoid filename truncation in numastat Date: Thu, 22 Mar 2018 12:33:20 -0600 Message-Id: <20180322183322.23076-1-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.14.3 MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.23 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 gcc 7.3.1 provides the following warning when compiling numastat.c: numastat.c: In function ‘add_pids_from_pattern_search’: numastat.c:1316:41: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 58 [-Wformat-truncation=] snprintf(fname, sizeof(fname), "/proc/%s/cmdline", namelist[ix]->d_name); ^~ numastat.c:1316:3: note: ‘snprintf’ output between 15 and 270 bytes into a destination of size 64 snprintf(fname, sizeof(fname), "/proc/%s/cmdline", namelist[ix]->d_name); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is valid - namelist[ix]->d_name is size 256 bytes, we have some extra bytes as part of our format string. Our destination buffer, 'fname', is only 64 bytes wide. Signed-off-by: Ross Zwisler --- numastat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numastat.c b/numastat.c index e0a5639..2d413df 100644 --- a/numastat.c +++ b/numastat.c @@ -1312,7 +1312,7 @@ void add_pids_from_pattern_search(char *pattern) { } // Next copy cmdline file contents onto end of buffer. Do it a // character at a time to convert nulls to spaces. - char fname[64]; + char fname[272]; snprintf(fname, sizeof(fname), "/proc/%s/cmdline", namelist[ix]->d_name); FILE *fs = fopen(fname, "r"); if (fs) {