X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FHand%2FLocate.c;h=d98b55ab9363b7951dd73fd1dad9d7592867d5df;hb=4e1005eca7186cbe61aaae09108f6fdf29959f22;hp=5a30c5264f5ab0a6fa6b8ed5bbbdea0d18b4efe7;hpb=81bf52d6d87e92f21678140322d32b726fc8f3b7;p=mirror_edk2.git diff --git a/MdeModulePkg/Core/Dxe/Hand/Locate.c b/MdeModulePkg/Core/Dxe/Hand/Locate.c index 5a30c5264f..d98b55ab93 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Locate.c +++ b/MdeModulePkg/Core/Dxe/Hand/Locate.c @@ -1,8 +1,8 @@ /** @file Locate handle functions -Copyright (c) 2006 - 2009, Intel Corporation.
-All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -200,6 +200,7 @@ CoreLocateHandle ( return Status; } + ASSERT (GetNext != NULL); // // Enumerate out the matching handles // @@ -246,6 +247,7 @@ CoreLocateHandle ( // If this is a search by register notify and a handle was // returned, update the register notification position // + ASSERT (SearchKey != NULL); ProtNotify = SearchKey; ProtNotify->Position = ProtNotify->Position->ForwardLink; } @@ -404,18 +406,19 @@ CoreGetNextLocateByProtocol ( /** - Locates the handle to a device on the device path that best matches the specified protocol. + Locates the handle to a device on the device path that supports the specified protocol. - @param Protocol The protocol to search for. - @param DevicePath On input, a pointer to a pointer to the device - path. On output, the device path pointer is - modified to point to the remaining part of the - devicepath. - @param Device A pointer to the returned device handle. + @param Protocol Specifies the protocol to search for. + @param DevicePath On input, a pointer to a pointer to the device path. On output, the device + path pointer is modified to point to the remaining part of the device + path. + @param Device A pointer to the returned device handle. - @retval EFI_SUCCESS The resulting handle was returned. - @retval EFI_NOT_FOUND No handles matched the search. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. + @retval EFI_SUCCESS The resulting handle was returned. + @retval EFI_NOT_FOUND No handles match the search. + @retval EFI_INVALID_PARAMETER Protocol is NULL. + @retval EFI_INVALID_PARAMETER DevicePath is NULL. + @retval EFI_INVALID_PARAMETER A handle matched the search and Device is NULL. **/ EFI_STATUS @@ -434,6 +437,7 @@ CoreLocateDevicePath ( EFI_STATUS Status; EFI_HANDLE *Handles; EFI_HANDLE Handle; + EFI_HANDLE BestDevice; EFI_DEVICE_PATH_PROTOCOL *SourcePath; EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; @@ -445,11 +449,8 @@ CoreLocateDevicePath ( return EFI_INVALID_PARAMETER; } - if (Device == NULL) { - return EFI_INVALID_PARAMETER; - } - - *Device = NULL; + Handles = NULL; + BestDevice = NULL; SourcePath = *DevicePath; TmpDevicePath = SourcePath; while (!IsDevicePathEnd (TmpDevicePath)) { @@ -488,7 +489,8 @@ CoreLocateDevicePath ( // Check if DevicePath is first part of SourcePath // Size = GetDevicePathSize (TmpDevicePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL); - if ((Size <= SourceSize) && CompareMem (SourcePath, TmpDevicePath, Size) == 0) { + ASSERT (Size >= 0); + if ((Size <= SourceSize) && CompareMem (SourcePath, TmpDevicePath, (UINTN) Size) == 0) { // // If the size is equal to the best match, then we // have a duplicate device path for 2 different device @@ -501,7 +503,7 @@ CoreLocateDevicePath ( // if (Size > BestMatch) { BestMatch = Size; - *Device = Handle; + BestDevice = Handle; } } } @@ -516,6 +518,11 @@ CoreLocateDevicePath ( return EFI_NOT_FOUND; } + if (Device == NULL) { + return EFI_INVALID_PARAMETER; + } + *Device = BestDevice; + // // Return the remaining part of the device path //