libefivar: Check Length para before use in DevPathToTextUsbWWID

In function DevPathToTextUsbWWID, the Length parameter is used
without check. This patch is to add check before using it.

Upstream Bug:	https://bugzilla.tianocore.org/show_bug.cgi?id=1336
Obtained from:	d8e702693a
Pull Request:   https://github.com/freebsd/freebsd-src/pull/581
This commit is contained in:
Jose Luis Duran 2022-02-23 17:16:15 -03:00 committed by Warner Losh
parent c1fa6f4c5d
commit e871598ad4

View File

@ -1033,7 +1033,7 @@ DevPathToTextUsbWWID (
SerialNumberStr = (CHAR16 *) (&UsbWWId + 1);
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
//