From: Jian J Wang Date: Fri, 25 Jan 2019 14:12:25 +0000 (+0800) Subject: MdePkg/UefiDevicePathLib: Add sanity check for FilePath device path X-Git-Tag: edk2-stable201903~83 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=2f7a96d6ec13b292d6f31295f3195913921173e1 MdePkg/UefiDevicePathLib: Add sanity check for 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 Reviewed-by: Liming Gao Reviewed-by: Ray Ni --- diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c index 5d7635fe3e..dd1bddc1c2 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c @@ -95,6 +95,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; + } } //