libefivar: Add sanity check for FilePath device path

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1497

Current implementation of IsDevicePathValid() is not enough for type
of MEDIA_FILEPATH_DP, which has NULL-terminated string in the device
path. This patch add a simple NULL character check at Length position.

Note that the link above no longer exists.  The commit message was kept
verbatim.  An archived version of the bug report can be found at:
https://web.archive.org/web/20240714191428/https://bugzilla.tianocore.org/show_bug.cgi?id=1497

Add the const keyword to avoid errors/warnings about dropping a const
qualifier.

Obtained from:	https://github.com/tianocore/edk2/commit/2f7a96d6ec13b292d6f31295f3195913921173e1

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1894
This commit is contained in:
Jose Luis Duran
2025-11-13 16:49:05 +00:00
committed by Warner Losh
parent fd606b629f
commit 5c2ae0a209
+10 -1
View File
@@ -37,7 +37,7 @@
/*
* Taken from MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
* hash fd02394228ee1dc2378cccfde6098c461f96dd42 2019-Jan-31
* hash 2f7a96d6ec13b292d6f31295f3195913921173e1 2019-Feb-21
*/
/** @file
@@ -137,6 +137,15 @@ IsDevicePathValid (
return FALSE;
}
}
//
// FilePath must be a NULL-terminated string.
//
if (DevicePathType (DevicePath) == MEDIA_DEVICE_PATH &&
DevicePathSubType (DevicePath) == MEDIA_FILEPATH_DP &&
*(const CHAR16 *)((const UINT8 *) DevicePath + NodeLength - 2) != 0) {
return FALSE;
}
}
//