From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A0ECC1A1E73 for ; Wed, 26 Oct 2016 23:36:35 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP; 26 Oct 2016 23:36:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,404,1473145200"; d="scan'208";a="184395098" Received: from shwde7156.ccr.corp.intel.com ([10.239.158.52]) by fmsmga004.fm.intel.com with ESMTP; 26 Oct 2016 23:36:34 -0700 From: Eric Dong To: edk2-devel@lists.01.org Cc: Ruiyu NI , Jiewen Yao Date: Thu, 27 Oct 2016 14:36:28 +0800 Message-Id: <1477550191-11836-2-git-send-email-eric.dong@intel.com> X-Mailer: git-send-email 2.6.4.windows.1 In-Reply-To: <1477550191-11836-1-git-send-email-eric.dong@intel.com> References: <1477550191-11836-1-git-send-email-eric.dong@intel.com> Subject: [Patch 1/4] MdePkg DevicePathLib: Rollback former change. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Oct 2016 06:36:35 -0000 Former patch still has some bugs, so rollback it and enhance the original code. Cc: Ruiyu NI Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong --- .../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