X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FUefiDevicePathLib%2FDevicePathUtilities.c;h=bb4a56398e3c92c6b249d765d90b3144f72f492c;hb=41bfaffd13094d9042110091e6c37adf20c4032c;hp=82419a4e1b2ae618aa061b5462e08a8e0b6d2030;hpb=e9fb71b29965aff2bf9e9caa1837ddcd069f2a27;p=mirror_edk2.git diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c index 82419a4e1b..bb4a56398e 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c @@ -61,16 +61,18 @@ IsDevicePathValid ( ASSERT (DevicePath != NULL); - if (MaxSize == 0){ + if (MaxSize == 0) { MaxSize = MAX_UINTN; } - Size = 0; - Count = 0; + // + // Validate the input size big enough to touch the first node. + // + if (MaxSize < sizeof (EFI_DEVICE_PATH_PROTOCOL)) { + return FALSE; + } - while (MaxSize >= sizeof (EFI_DEVICE_PATH_PROTOCOL) && - (MaxSize - sizeof (EFI_DEVICE_PATH_PROTOCOL) >= Size) && - !IsDevicePathEnd (DevicePath)) { + for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) { NodeLength = DevicePathNodeLength (DevicePath); if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) { return FALSE; @@ -79,17 +81,21 @@ IsDevicePathValid ( if (NodeLength > MAX_UINTN - Size) { return FALSE; } - Size += NodeLength; + // + // Validate next node before touch it. + // + if (Size > MaxSize - END_DEVICE_PATH_LENGTH ) { + return FALSE; + } + if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) { Count++; if (Count >= PcdGet32 (PcdMaximumDevicePathNodeCount)) { return FALSE; } } - - DevicePath = NextDevicePathNode (DevicePath); } //