From d8e702693a8c292220131dc4234a36e2c9fff614 Mon Sep 17 00:00:00 2001 From: Dandan Bi Date: Mon, 19 Nov 2018 09:33:14 +0800 Subject: [PATCH] MdePkg: check Length para before use in DevPathToTextUsbWWID REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1336 In function DevPathToTextUsbWWID, the Length parameter is used without check. This patch is to add check before using it. Cc: Michael D Kinney Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Dandan Bi Reviewed-by: Liming Gao --- MdePkg/Library/UefiDevicePathLib/DevicePathToText.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c index 97d279eeb2..678f3d0a92 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c @@ -972,7 +972,7 @@ DevPathToTextUsbWWID ( SerialNumberStr = (CHAR16 *) ((UINT8 *) UsbWWId + sizeof (USB_WWID_DEVICE_PATH)); Length = (UINT16) ((DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) UsbWWId) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16)); - if (SerialNumberStr [Length - 1] != 0) { + if (Length >= 1 && SerialNumberStr [Length - 1] != 0) { // // In case no NULL terminator in SerialNumber, create a new one with NULL terminator // -- 2.39.2