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.115; helo=mga14.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 2A405201B0423 for ; Tue, 19 Feb 2019 01:21:46 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Feb 2019 01:21:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,387,1544515200"; d="scan'208";a="320183123" Received: from shwdeopenpsi777.ccr.corp.intel.com ([10.239.158.28]) by fmsmga006.fm.intel.com with ESMTP; 19 Feb 2019 01:21:45 -0800 From: Jian J Wang To: edk2-devel@lists.01.org Cc: Liming Gao , Ray Ni , Michael D Kinney Date: Tue, 19 Feb 2019 17:21:39 +0800 Message-Id: <20190219092139.844-3-jian.j.wang@intel.com> X-Mailer: git-send-email 2.17.1.windows.2 In-Reply-To: <20190219092139.844-1-jian.j.wang@intel.com> References: <20190219092139.844-1-jian.j.wang@intel.com> Subject: [PATCH v2 2/2] MdePkg/UefiDevicePathLibDevicePathProtocol: Add sanity check for FilePath device path 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: Tue, 19 Feb 2019 09:21:46 -0000 > v2: fix wrong detection of FilePath device path REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1497 Current implementation of IsDevicePathValid() is not enough for type of MEDIA_FILEPATH_DP, which has NULL-terminated string in the device path. This patch add a simple NULL character check at Length position. Cc: Liming Gao Cc: Ray Ni Cc: Michael D Kinney Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- .../UefiDevicePathLib.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c index 9a0ee42fd1..c8e78d2373 100644 --- a/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c +++ b/MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c @@ -138,6 +138,15 @@ IsDevicePathValid ( return FALSE; } } + + // + // FilePath must be a NULL-terminated string. + // + if (DevicePathType (DevicePath) == MEDIA_DEVICE_PATH && + DevicePathSubType (DevicePath) == MEDIA_FILEPATH_DP && + *(CHAR16 *)((UINT8 *)DevicePath + NodeLength - 2) != 0) { + return FALSE; + } } // -- 2.17.1.windows.2