]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/UefiDevicePathLib: Add a checking step
authorMike Turner <miketur@microsoft.com>
Tue, 11 Dec 2018 06:14:10 +0000 (14:14 +0800)
committerLiming Gao <liming.gao@intel.com>
Thu, 31 Jan 2019 12:19:21 +0000 (20:19 +0800)
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: Liming Gao <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
MdePkg/Include/Library/DevicePathLib.h
MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c

index 959299704a5d3742c8607f8915b52419fef2b5f7..670e7b0424468aed0dc5ea1a1b8f165e1ce023c0 100644 (file)
@@ -22,12 +22,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 /**\r
   Determine whether a given device path is valid.\r
-  If DevicePath is NULL, then ASSERT().\r
 \r
   @param  DevicePath  A pointer to a device path data structure.\r
   @param  MaxSize     The maximum size of the device path data structure.\r
 \r
   @retval TRUE        DevicePath is valid.\r
+  @retval FALSE       DevicePath is NULL.\r
+  @retval FALSE       Maxsize is less than sizeof(EFI_DEVICE_PATH_PROTOCOL).\r
   @retval FALSE       The length of any node node in the DevicePath is less\r
                       than sizeof (EFI_DEVICE_PATH_PROTOCOL).\r
   @retval FALSE       If MaxSize is not zero, the size of the DevicePath\r
index 665e5a4adcd392a3d07398c5ad4bba4d4190b7f8..5d7635fe3eddcb17b0923a97384bffc386387671 100644 (file)
@@ -35,12 +35,13 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_PROTOCOL  mUefiDevicePathLib
 \r
 /**\r
   Determine whether a given device path is valid.\r
-  If DevicePath is NULL, then ASSERT().\r
 \r
   @param  DevicePath  A pointer to a device path data structure.\r
   @param  MaxSize     The maximum size of the device path data structure.\r
 \r
   @retval TRUE        DevicePath is valid.\r
+  @retval FALSE       DevicePath is NULL.\r
+  @retval FALSE       Maxsize is less than sizeof(EFI_DEVICE_PATH_PROTOCOL).\r
   @retval FALSE       The length of any node node in the DevicePath is less\r
                       than sizeof (EFI_DEVICE_PATH_PROTOCOL).\r
   @retval FALSE       If MaxSize is not zero, the size of the DevicePath\r
@@ -59,19 +60,17 @@ IsDevicePathValid (
   UINTN Size;\r
   UINTN NodeLength;\r
 \r
-  ASSERT (DevicePath != NULL);\r
-\r
-  if (MaxSize == 0) {\r
-    MaxSize = MAX_UINTN;\r
-  }\r
-\r
   //\r
-  // Validate the input size big enough to touch the first node.\r
+  //Validate the input whether exists and its size big enough to touch the first node\r
   //\r
-  if (MaxSize < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
+  if (DevicePath == NULL || (MaxSize > 0 && MaxSize < END_DEVICE_PATH_LENGTH)) {\r
     return FALSE;\r
   }\r
 \r
+  if (MaxSize == 0) {\r
+    MaxSize = MAX_UINTN;\r
+  }\r
+\r
   for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {\r
     NodeLength = DevicePathNodeLength (DevicePath);\r
     if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r