fix(variables): add null terminator to the end of strings written into variables

This commit is contained in:
2025-10-30 23:15:18 -04:00
parent 0368a170a8
commit a2f017ba30
2 changed files with 6 additions and 2 deletions

View File

@@ -85,8 +85,10 @@ impl BootloaderInterface {
.encode_utf16()
.flat_map(|c| c.to_le_bytes())
.collect::<Vec<u8>>();
// Write the bytes (including the null terminator) into the data buffer.
// Write the bytes into the data buffer.
data.extend_from_slice(&encoded);
// Add a null terminator to the end of the entry.
data.push(0);
}
Self::VENDOR.set(
"LoaderEntries",

View File

@@ -84,10 +84,12 @@ impl VariableController {
/// a [CString16]. The variable `class` controls the attributes for the variable.
pub fn set_cstr16(&self, key: &str, value: &str, class: VariableClass) -> Result<()> {
// Encode the value as a CString16 little endian.
let encoded = value
let mut encoded = value
.encode_utf16()
.flat_map(|c| c.to_le_bytes())
.collect::<Vec<u8>>();
// Add a null terminator to the end of the value.
encoded.push(0);
self.set(key, &encoded, class)
}