From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=shenglei.zhang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D381A2119BBCE for ; Tue, 11 Dec 2018 19:10:16 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 19:10:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,343,1539673200"; d="scan'208";a="127138119" Received: from shenglei-dev.ccr.corp.intel.com ([10.239.158.52]) by fmsmga004.fm.intel.com with ESMTP; 11 Dec 2018 19:10:16 -0800 From: Shenglei Zhang To: edk2-devel@lists.01.org Cc: Liming Gao , Michael D Kinney Date: Wed, 12 Dec 2018 11:10:11 +0800 Message-Id: <20181212031011.20996-3-shenglei.zhang@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20181212031011.20996-1-shenglei.zhang@intel.com> References: <20181212031011.20996-1-shenglei.zhang@intel.com> Subject: [PATCH v2 2/2] MdePkg/UefiDevicePathLib: Add a checking step X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Dec 2018 03:10:17 -0000 Add a checking step in DevicePathUtilities.c to verify the DevicePath. https://bugzilla.tianocore.org/show_bug.cgi?id=1372 v2: Remove ASSERT() and the redundant checking step. Update related description in DevicePathLib.h Cc: Liming Gao Cc: Michael D Kinney Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Shenglei Zhang --- MdePkg/Include/Library/DevicePathLib.h | 2 +- .../UefiDevicePathLib/DevicePathUtilities.c | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/MdePkg/Include/Library/DevicePathLib.h b/MdePkg/Include/Library/DevicePathLib.h index 959299704a..717d4db42f 100644 --- a/MdePkg/Include/Library/DevicePathLib.h +++ b/MdePkg/Include/Library/DevicePathLib.h @@ -22,7 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. /** Determine whether a given device path is valid. - If DevicePath is NULL, then ASSERT(). + If DevicePath is NULL or the size is not suitable, then return false. @param DevicePath A pointer to a device path data structure. @param MaxSize The maximum size of the device path data structure. diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c index 665e5a4adc..05f82c1313 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c @@ -59,19 +59,17 @@ IsDevicePathValid ( UINTN Size; UINTN NodeLength; - ASSERT (DevicePath != NULL); - - if (MaxSize == 0) { - MaxSize = MAX_UINTN; - } - // - // Validate the input size big enough to touch the first node. + //Validate the input whether exists and its size big enough to touch the first node // - if (MaxSize < sizeof (EFI_DEVICE_PATH_PROTOCOL)) { + if (DevicePath == NULL || (MaxSize > 0 && MaxSize < END_DEVICE_PATH_LENGTH)) { return FALSE; } + if (MaxSize == 0) { + MaxSize = MAX_UINTN; + } + for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) { NodeLength = DevicePathNodeLength (DevicePath); if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) { -- 2.18.0.windows.1