]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg UefiDevicePathLibDevicePathProtocol: Validate before use.
authorEric Dong <eric.dong@intel.com>
Wed, 12 Oct 2016 12:34:05 +0000 (20:34 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Wed, 19 Oct 2016 02:20:05 +0000 (10:20 +0800)
In IsDevicePathValid API, code should validate the device path
buffer not exceed the input MaxSize before reference the path
info.

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

index 5cc4b35fe492e3ed9fddc40799a109add92684b7..48724160d4b287978611fab75144ba1ecbdba0ca 100644 (file)
@@ -2,7 +2,7 @@
   Library instance that implement UEFI Device Path Library class based on protocol\r
   gEfiDevicePathUtilitiesProtocolGuid.\r
 \r
-  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -103,25 +103,35 @@ IsDevicePathValid (
 \r
   ASSERT (DevicePath != NULL);\r
 \r
-  for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {\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
     NodeLength = DevicePathNodeLength (DevicePath);\r
     if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {\r
       return FALSE;\r
     }\r
 \r
-    if (MaxSize > 0) {\r
-      Size += NodeLength;\r
-      if (Size + END_DEVICE_PATH_LENGTH > MaxSize) {\r
-        return FALSE;\r
-      }\r
+    if (NodeLength > MAX_UINTN - Size) {\r
+      return FALSE;\r
     }\r
 \r
+    Size += NodeLength;\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