libefivar: Add a checking step

Add a checking step in DevicePathUtilities.c to verify DevicePath.
https://bugzilla.tianocore.org/show_bug.cgi?id=1372

v2: Remove ASSERT() and the redundant checking step. Update related
    description.

Note that the link above no longer exists.  The commit message was kept
verbatim.  An archived version of the bug report can be found at:
https://web.archive.org/web/20240714192353/bugzilla.tianocore.org/show_bug.cgi?id=1372

Obtained from:	https://github.com/tianocore/edk2/commit/fd02394228ee1dc2378cccfde6098c461f96dd42

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1894
This commit is contained in:
Jose Luis Duran
2025-11-13 16:45:16 +00:00
committed by Warner Losh
parent 9677ae7864
commit fd606b629f
+9 -10
View File
@@ -37,7 +37,7 @@
/*
* Taken from MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
* hash 9095d37b8fe5bfc3d02adad6ba7fd7359ebc0107 2018-Jun-28
* hash fd02394228ee1dc2378cccfde6098c461f96dd42 2019-Jan-31
*/
/** @file
@@ -77,12 +77,13 @@ static CONST EFI_DEVICE_PATH_PROTOCOL mUefiDevicePathLibEndDevicePath = {
/**
Determine whether a given device path is valid.
If DevicePath is NULL, then ASSERT().
@param DevicePath A pointer to a device path data structure.
@param MaxSize The maximum size of the device path data structure.
@retval TRUE DevicePath is valid.
@retval FALSE DevicePath is NULL.
@retval FALSE Maxsize is less than sizeof(EFI_DEVICE_PATH_PROTOCOL).
@retval FALSE The length of any node Node in the DevicePath is less
than sizeof (EFI_DEVICE_PATH_PROTOCOL).
@retval FALSE If MaxSize is not zero, the size of the DevicePath
@@ -101,19 +102,17 @@ IsDevicePathValid (
UINTN Size;
UINTN NodeLength;
ASSERT (DevicePath != NULL);
//
//Validate the input whether exists and its size big enough to touch the first node
//
if (DevicePath == NULL || (MaxSize > 0 && MaxSize < END_DEVICE_PATH_LENGTH)) {
return FALSE;
}
if (MaxSize == 0) {
MaxSize = MAX_UINTN;
}
//
// Validate the input size big enough to touch the first node.
//
if (MaxSize < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
return FALSE;
}
for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {
NodeLength = DevicePathNodeLength (DevicePath);
if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {