]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg DevicePathLib: Rollback former change.
authorEric Dong <eric.dong@intel.com>
Thu, 27 Oct 2016 03:05:51 +0000 (11:05 +0800)
committerStar Zeng <star.zeng@intel.com>
Wed, 9 Nov 2016 09:49:14 +0000 (17:49 +0800)
Former patch still has some bugs, so rollback it and
enhance the original code.

Cc: Ruiyu NI <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c

index 48724160d4b287978611fab75144ba1ecbdba0ca..a514f1b6f9beff50af0221b3b78b7699a4d66734 100644 (file)
@@ -103,35 +103,25 @@ IsDevicePathValid (
 \r
   ASSERT (DevicePath != NULL);\r
 \r
 \r
   ASSERT (DevicePath != NULL);\r
 \r
-  if (MaxSize == 0){\r
-    MaxSize = MAX_UINTN;\r
-  }\r
-\r
-  Size = 0;\r
-  Count = 0;\r
-\r
-  while (MaxSize >= sizeof (EFI_DEVICE_PATH_PROTOCOL) &&\r
-        (MaxSize - sizeof (EFI_DEVICE_PATH_PROTOCOL) >= Size) &&\r
-        !IsDevicePathEnd (DevicePath)) {\r
+  for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {\r
     NodeLength = DevicePathNodeLength (DevicePath);\r
     if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
       return FALSE;\r
     }\r
 \r
     NodeLength = DevicePathNodeLength (DevicePath);\r
     if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
       return FALSE;\r
     }\r
 \r
-    if (NodeLength > MAX_UINTN - Size) {\r
-      return FALSE;\r
+    if (MaxSize > 0) {\r
+      Size += NodeLength;\r
+      if (Size + END_DEVICE_PATH_LENGTH > MaxSize) {\r
+        return FALSE;\r
+      }\r
     }\r
 \r
     }\r
 \r
-    Size += NodeLength;\r
-\r
     if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) {\r
       Count++;\r
       if (Count >= PcdGet32 (PcdMaximumDevicePathNodeCount)) {\r
         return FALSE;\r
       }\r
     }\r
     if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) {\r
       Count++;\r
       if (Count >= PcdGet32 (PcdMaximumDevicePathNodeCount)) {\r
         return FALSE;\r
       }\r
     }\r
-\r
-    DevicePath = NextDevicePathNode (DevicePath);\r
   }\r
 \r
   //\r
   }\r
 \r
   //\r