ShellPkg/UefiHandleParsingLib: fix retval for empty child controller array

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 <jaben.carsey@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Tapan Shah <tapandshah@hpe.com>
Reported-by: Tapan Shah <tapandshah@hpe.com>
Ref: https://tianocore.acgmultimedia.com/show_bug.cgi?id=112
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
This commit is contained in:
Laszlo Ersek 2016-09-08 16:57:02 +02:00
parent b6c5420461
commit 7eb3bb6c55
1 changed files with 9 additions and 2 deletions

View File

@ -2802,11 +2802,18 @@ ParseHandleDatabaseForChildControllers(
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));