From patchwork Thu Sep 8 16:14:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 75809 Delivered-To: patch@linaro.org Received: by 10.140.106.11 with SMTP id d11csp931763qgf; Thu, 8 Sep 2016 09:14:27 -0700 (PDT) X-Received: by 10.98.93.204 with SMTP id n73mr719355pfj.87.1473351267764; Thu, 08 Sep 2016 09:14:27 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id fx20si3399301pab.220.2016.09.08.09.14.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Sep 2016 09:14:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 60E1A1A1E56; Thu, 8 Sep 2016 09:14:27 -0700 (PDT) X-Original-To: edk2-devel@ml01.01.org Delivered-To: edk2-devel@ml01.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 63F681A1E4F for ; Thu, 8 Sep 2016 09:14:24 -0700 (PDT) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C41D7C030713; Thu, 8 Sep 2016 16:14:23 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-57.phx2.redhat.com [10.3.116.57]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u88GEIF5030512; Thu, 8 Sep 2016 12:14:22 -0400 From: Laszlo Ersek To: edk2-devel@ml01.01.org Date: Thu, 8 Sep 2016 18:14:14 +0200 Message-Id: <20160908161414.3143-3-lersek@redhat.com> In-Reply-To: <20160908161414.3143-1-lersek@redhat.com> References: <20160908161414.3143-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 08 Sep 2016 16:14:23 +0000 (UTC) Subject: [edk2] [PATCH 2/2] ShellPkg/UefiHandleParsingLib: fix retval for empty child controller array X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jaben Carsey , Ruiyu Ni MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The ParseHandleDatabaseForChildControllers() function intends to work like this: (1) It allocates a "HandleBufferForReturn" local array that's guaranteed to be big enough for all found handles, (2) it collects the handles, both counting them in the (mandatory) "MatchingHandleCount" output parameter, and saving them in the local "HandleBufferForReturn" array, (3) if the caller is not interested in the actual handles, then "HandleBufferForReturn" is released, (4) if the caller is interested in the handles, and we've found some, then "HandleBufferForReturn" is passed out through the "MatchingHandleBuffer" output parameter, (5) if the caller is interested in the actual handles, but we've found none, then the "MatchingHandleBuffer" output parameter is set to NULL. The ASSERT() at the end of the function makes this clear, but the implementation does not conform to (5). Fix it. Cc: Jaben Carsey Cc: Ruiyu Ni Cc: Tapan Shah Reported-by: Tapan Shah Ref: https://tianocore.acgmultimedia.com/show_bug.cgi?id=112 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) -- 2.9.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c index e11a3ccceab3..695d090926e1 100644 --- a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c +++ b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c @@ -2799,17 +2799,24 @@ ParseHandleDatabaseForChildControllers( FreePool (ChildControllerHandleBuffer); } FreePool (DriverBindingHandleBuffer); + if (MatchingHandleBuffer == NULL || *MatchingHandleCount == 0) { + // + // The caller is not interested in the actual handles, or we've found none. + // + FreePool (HandleBufferForReturn); + HandleBufferForReturn = NULL; + } + if (MatchingHandleBuffer != NULL) { *MatchingHandleBuffer = HandleBufferForReturn; - } else { - FreePool(HandleBufferForReturn); } + ASSERT ((MatchingHandleBuffer == NULL) || (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) || (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL)); return (EFI_SUCCESS); }