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 <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>
This commit is contained in:
Dandan Bi 2018-11-19 09:33:14 +08:00 committed by Liming Gao
parent 63f151aadb
commit d8e702693a

View File

@ -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
//