From patchwork Sat Apr 8 03:03:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 9670929 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 2D9DC6021C for ; Sat, 8 Apr 2017 03:03:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2264328497 for ; Sat, 8 Apr 2017 03:03:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 170AB284DA; Sat, 8 Apr 2017 03:03: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=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, UNPARSEABLE_RELAY 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 B106A28497 for ; Sat, 8 Apr 2017 03:03:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750857AbdDHDDx (ORCPT ); Fri, 7 Apr 2017 23:03:53 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:26103 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750717AbdDHDDx (ORCPT ); Fri, 7 Apr 2017 23:03:53 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v3833ouM026956 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 8 Apr 2017 03:03:50 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v3833oF8029532 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 8 Apr 2017 03:03:50 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v3833oHi028345; Sat, 8 Apr 2017 03:03:50 GMT Received: from localhost (/24.21.211.40) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 07 Apr 2017 20:03:49 -0700 Subject: [PATCH 1/4] xfs_db: don't print arrays off the end of a buffer From: "Darrick J. Wong" To: sandeen@redhat.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Fri, 07 Apr 2017 20:03:48 -0700 Message-ID: <149162062896.22901.1082958527237251943.stgit@birch.djwong.org> In-Reply-To: <149162062276.22901.7801103937404880951.stgit@birch.djwong.org> References: <149162062276.22901.7801103937404880951.stgit@birch.djwong.org> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Before printing an array, clamp the array count against the size of the buffer so that we don't print random heap contents. Signed-off-by: Darrick J. Wong --- db/print.c | 11 +++++++++++ 1 file changed, 11 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/db/print.c b/db/print.c index e31372f..0caad8f 100644 --- a/db/print.c +++ b/db/print.c @@ -144,6 +144,17 @@ print_flist_1( if (fl->flags & FL_OKHIGH) count = min(count, fl->high - low + 1); if (fa->prfunc) { + int fsz; + int bitlen; + + /* Don't read an array off the end of the buffer */ + fsz = fsize(f, iocur_top->data, parentoff, 0); + bitlen = iocur_top->len * NBBY; + if ((f->flags & FLD_ARRAY) && + fl->offset + (count * fsz) > bitlen) { + count = (bitlen - fl->offset) / fsz; + } + neednl = fa->prfunc(iocur_top->data, fl->offset, count, fa->fmtstr, fsize(f, iocur_top->data, parentoff, 0),