public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Eric Dong <eric.dong@intel.com>
To: edk2-devel@lists.01.org
Cc: Ruiyu NI <ruiyu.ni@intel.com>, Jiewen Yao <jiewen.yao@intel.com>
Subject: [Patch 1/4] MdePkg DevicePathLib: Rollback former change.
Date: Thu, 27 Oct 2016 14:36:28 +0800	[thread overview]
Message-ID: <1477550191-11836-2-git-send-email-eric.dong@intel.com> (raw)
In-Reply-To: <1477550191-11836-1-git-send-email-eric.dong@intel.com>

Former patch still has some bugs, so rollback it and
enhance the original code.

Cc: Ruiyu NI <ruiyu.ni@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <eric.dong@intel.com>
---
 .../UefiDevicePathLib.c                            | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
index 4872416..a514f1b 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);
   }
 
   //
-- 
2.6.4.windows.1



  reply	other threads:[~2016-10-27  6:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-27  6:36 [Patch 0/4] Enhance IsDevciePathValid API Eric Dong
2016-10-27  6:36 ` Eric Dong [this message]
2016-10-27  6:36 ` [Patch 2/4] MdePkg DevicePathLib: Validate before touch input buffer Eric Dong
2016-10-27  6:36 ` [Patch 3/4] MdePkg UefiDevicePathLib: Rollback former change Eric Dong
2016-10-27  6:36 ` [Patch 4/4] MdePkg UefiDevicePathLib: Validate before touch input buffer Eric Dong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1477550191-11836-2-git-send-email-eric.dong@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox