]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg: check Length para before use in DevPathToTextUsbWWID
authorDandan Bi <dandan.bi@intel.com>
Mon, 19 Nov 2018 01:33:14 +0000 (09:33 +0800)
committerLiming Gao <liming.gao@intel.com>
Wed, 21 Nov 2018 05:01:02 +0000 (13:01 +0800)
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 <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdePkg/Library/UefiDevicePathLib/DevicePathToText.c

index 97d279eeb25b711090881b53e3939698492b2c69..678f3d0a922de61eb8a94c2bdd02b52668d5de9e 100644 (file)
@@ -972,7 +972,7 @@ DevPathToTextUsbWWID (
 \r
   SerialNumberStr = (CHAR16 *) ((UINT8 *) UsbWWId + sizeof (USB_WWID_DEVICE_PATH));\r
   Length = (UINT16) ((DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) UsbWWId) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16));\r
-  if (SerialNumberStr [Length - 1] != 0) {\r
+  if (Length >= 1 && SerialNumberStr [Length - 1] != 0) {\r
     //\r
     // In case no NULL terminator in SerialNumber, create a new one with NULL terminator\r
     //\r