Skip to content

Commit a2f017b

Browse files
committed
fix(variables): add null terminator to the end of strings written into variables
1 parent 0368a17 commit a2f017b

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/integrations/bootloader_interface.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ impl BootloaderInterface {
8585
.encode_utf16()
8686
.flat_map(|c| c.to_le_bytes())
8787
.collect::<Vec<u8>>();
88-
// Write the bytes (including the null terminator) into the data buffer.
88+
// Write the bytes into the data buffer.
8989
data.extend_from_slice(&encoded);
90+
// Add a null terminator to the end of the entry.
91+
data.push(0);
9092
}
9193
Self::VENDOR.set(
9294
"LoaderEntries",

src/utils/variables.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@ impl VariableController {
8484
/// a [CString16]. The variable `class` controls the attributes for the variable.
8585
pub fn set_cstr16(&self, key: &str, value: &str, class: VariableClass) -> Result<()> {
8686
// Encode the value as a CString16 little endian.
87-
let encoded = value
87+
let mut encoded = value
8888
.encode_utf16()
8989
.flat_map(|c| c.to_le_bytes())
9090
.collect::<Vec<u8>>();
91+
// Add a null terminator to the end of the value.
92+
encoded.push(0);
9193
self.set(key, &encoded, class)
9294
}
9395

0 commit comments

Comments
 (0)