summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Dong <eric.dong@intel.com>2016-10-27 11:05:51 +0800
committerStar Zeng <star.zeng@intel.com>2016-11-09 17:49:14 +0800
commit1420143f014a4c14bd7cb430aaacd6b2c4bc8043 (patch)
tree2faaf95ea823a1aa3cb8e9eff1cabfa0227c5b48
parent49d8f534cc4280fa3f393dec5093b23b0c759c2c (diff)
downloadedk2-platforms-1420143f014a4c14bd7cb430aaacd6b2c4bc8043.tar.xz
MdePkg DevicePathLib: Rollback former change.
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>
-rw-r--r--MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
index 48724160d4..a514f1b6f9 100644
--- a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
+++ b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
@@ -103,35 +103,25 @@ IsDevicePathValid (
ASSERT (DevicePath != NULL);
- if (MaxSize == 0){
- MaxSize = MAX_UINTN;
- }
-
- Size = 0;
- Count = 0;
-
- while (MaxSize >= sizeof (EFI_DEVICE_PATH_PROTOCOL) &&
- (MaxSize - sizeof (EFI_DEVICE_PATH_PROTOCOL) >= Size) &&
- !IsDevicePathEnd (DevicePath)) {
+ for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {
NodeLength = DevicePathNodeLength (DevicePath);
if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
return FALSE;
}
- if (NodeLength > MAX_UINTN - Size) {
- return FALSE;
+ if (MaxSize > 0) {
+ Size += NodeLength;
+ if (Size + END_DEVICE_PATH_LENGTH > MaxSize) {
+ return FALSE;
+ }
}
- Size += NodeLength;
-
if (PcdGet32 (PcdMaximumDevicePathNodeCount) > 0) {
Count++;
if (Count >= PcdGet32 (PcdMaximumDevicePathNodeCount)) {
return FALSE;
}
}
-
- DevicePath = NextDevicePathNode (DevicePath);
}
//