From patchwork Wed Aug 8 22:21:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 10560543 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD50214C0 for ; Wed, 8 Aug 2018 22:25:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EB682ADA3 for ; Wed, 8 Aug 2018 22:25:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 920B42ADE5; Wed, 8 Aug 2018 22:25:08 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 528262ADA3 for ; Wed, 8 Aug 2018 22:25:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1C782307D863; Wed, 8 Aug 2018 22:25:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E6F8719682; Wed, 8 Aug 2018 22:25:06 +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 9AE154A465; Wed, 8 Aug 2018 22:25:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w78MLrwB009393 for ; Wed, 8 Aug 2018 18:21:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 54BB11C73D; Wed, 8 Aug 2018 22:21:53 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with SMTP id 240FB1C73E; Wed, 8 Aug 2018 22:21:52 +0000 (UTC) Received: by redhat.com (sSMTP sendmail emulation); Wed, 08 Aug 2018 17:21:51 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Wed, 8 Aug 2018 17:21:26 -0500 Message-Id: <1533766895-28605-9-git-send-email-bmarzins@redhat.com> In-Reply-To: <1533766895-28605-1-git-send-email-bmarzins@redhat.com> References: <1533766895-28605-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: dm-devel@redhat.com Cc: Martin Wilck Subject: [dm-devel] [PATCH v2 08/17] libmultipath: _install_keyword cleanup 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: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 08 Aug 2018 22:25:07 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP _install_keyword should use VECTOR_LAST_SLOT(), which has better error checking. It should also fail if it gets a NULL pointer, instead of dereferencing it. Found by coverity. Signed-off-by: Benjamin Marzinski --- libmultipath/parser.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libmultipath/parser.c b/libmultipath/parser.c index b8b7e0d..92ef7cf 100644 --- a/libmultipath/parser.c +++ b/libmultipath/parser.c @@ -79,12 +79,16 @@ _install_keyword(vector keywords, char *string, struct keyword *keyword; /* fetch last keyword */ - keyword = VECTOR_SLOT(keywords, VECTOR_SIZE(keywords) - 1); + keyword = VECTOR_LAST_SLOT(keywords); + if (!keyword) + return 1; /* position to last sub level */ - for (i = 0; i < sublevel; i++) - keyword = - VECTOR_SLOT(keyword->sub, VECTOR_SIZE(keyword->sub) - 1); + for (i = 0; i < sublevel; i++) { + keyword = VECTOR_LAST_SLOT(keyword->sub); + if (!keyword) + return 1; + } /* First sub level allocation */ if (!keyword->sub)