From patchwork Tue Dec 5 23:56:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 10094167 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 491286020F for ; Tue, 5 Dec 2017 23:57:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AC09295C8 for ; Tue, 5 Dec 2017 23:57:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CD6D299D3; Tue, 5 Dec 2017 23:57:11 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF8E6295C8 for ; Tue, 5 Dec 2017 23:57:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753052AbdLEX5I (ORCPT ); Tue, 5 Dec 2017 18:57:08 -0500 Received: from mga01.intel.com ([192.55.52.88]:65530 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753112AbdLEX5H (ORCPT ); Tue, 5 Dec 2017 18:57:07 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Dec 2017 15:57:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,365,1508828400"; d="scan'208";a="181701312" Received: from theros.lm.intel.com ([10.232.112.77]) by orsmga005.jf.intel.com with ESMTP; 05 Dec 2017 15:57:05 -0800 From: Ross Zwisler To: linux-xfs Cc: Ross Zwisler , linux-nvdimm , fstests , Jan Kara , Dave Chinner , Dan Williams , "Darrick J . Wong" Subject: [xfsprogs PATCH v2 1/3] xfs_io: fix compiler warnings in getfsmap code Date: Tue, 5 Dec 2017 16:56:49 -0700 Message-Id: <20171205235651.17102-2-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171205235651.17102-1-ross.zwisler@linux.intel.com> References: <20171205235651.17102-1-ross.zwisler@linux.intel.com> MIME-Version: 1.0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I recently upgraded my compiler from gcc (GCC) 6.4.1 20170727 (Red Hat 6.4.1-1) to gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2) and started getting a bunch of compiler warnings in io/fsmap.c: fsmap.c: In function ‘fsmap_f’: fsmap.c:228:40: warning: ‘%lld’ directive output may be truncated writing between 1 and 17 bytes into a region of size between 12 and 28 [-Wformat-truncation=] snprintf(bbuf, sizeof(bbuf), "[%lld..%lld]:", ^~~~ fsmap.c:228:32: note: directive argument in the range [0, 36028797018963967] snprintf(bbuf, sizeof(bbuf), "[%lld..%lld]:", ^~~~~~~~~~~~~~~ fsmap.c:228:3: note: ‘snprintf’ output between 8 and 40 bytes into a destination of size 32 snprintf(bbuf, sizeof(bbuf), "[%lld..%lld]:", ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (long long)BTOBBT(p->fmr_physical), ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (long long)BTOBBT(p->fmr_physical + p->fmr_length - 1)); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The issue is that 'bbuf' is only defined to be 32 characters wide, but each signed long long can potentially print as many as 19 characters (9223372036854775807 is the max value). The format we're using for bbuf is "[%lld..%lld]:" which has 2 signed long longs plus 6 other characters "[..]:\0", which means it's possible we'll print up to 44 characters, overflowing our 32 char buffer. Fix this by bumping all the buffer sizes in dump_map_verbose() to 64 characters. Signed-off-by: Ross Zwisler Cc: Darrick J. Wong Fixes: 3fcab549a234 ("xfs_io: support the new getfsmap ioctl") Reviewed-by: Darrick J. Wong --- io/fsmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io/fsmap.c b/io/fsmap.c index 448fb535..3d8a6700 100644 --- a/io/fsmap.c +++ b/io/fsmap.c @@ -184,8 +184,8 @@ dump_map_verbose( off64_t agoff, bperag; int foff_w, boff_w, aoff_w, tot_w, agno_w, own_w; int nr_w, dev_w; - char rbuf[32], bbuf[32], abuf[32], obuf[32]; - char nbuf[32], dbuf[32], gbuf[32]; + char rbuf[64], bbuf[64], abuf[64], obuf[64]; + char nbuf[64], dbuf[64], gbuf[64]; char owner[OWNER_BUF_SZ]; int sunit, swidth; int flg = 0;