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.
Cc: Bob Feng <[email protected]>
Cc: Liming Gao <[email protected]>
Cc: Yonghong Zhu <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Shenglei Zhang <[email protected]>
---
.../Source/C/DevicePath/DevicePathUtilities.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/BaseTools/Source/C/DevicePath/DevicePathUtilities.c
b/BaseTools/Source/C/DevicePath/DevicePathUtilities.c
index f8a41ff97d..e0399cfea7 100644
--- a/BaseTools/Source/C/DevicePath/DevicePathUtilities.c
+++ b/BaseTools/Source/C/DevicePath/DevicePathUtilities.c
@@ -36,12 +36,13 @@ 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
@@ -59,17 +60,15 @@ 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_UINT32;
- }
-
- //
- // 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)) {
--
2.18.0.windows.1
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel