From e871598ad4493991404bbaa030f66bfe32aca892 Mon Sep 17 00:00:00 2001 From: Jose Luis Duran Date: Wed, 23 Feb 2022 17:16:15 -0300 Subject: [PATCH] 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: https://github.com/tianocore/edk2/commit/d8e702693a8c292220131dc4234a36e2c9fff614 Pull Request: https://github.com/freebsd/freebsd-src/pull/581 --- lib/libefivar/efivar-dp-format.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libefivar/efivar-dp-format.c b/lib/libefivar/efivar-dp-format.c index 9c1969d81423..c3fa492d4c24 100644 --- a/lib/libefivar/efivar-dp-format.c +++ b/lib/libefivar/efivar-dp-format.c @@ -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 //