]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: fix off-by-one truncation when reading efivars
authorLuca Boccassi <luca.boccassi@gmail.com>
Sun, 17 May 2026 23:17:27 +0000 (00:17 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 18 May 2026 06:26:44 +0000 (08:26 +0200)
'val' is allocated as 'size + 1', so the NUL terminator must be written
to 'size', rather than 'size - 1'.

Follow-up for fab82756462fd0ce82836e3d95721954d7ab2527

src/boot/efi-efivars.c

index 5581d98ec35022622f70c700a3b5efe60d775d3b..c1ae4252c3c349bcc8453cd0c194e79b4f8bbb1f 100644 (file)
@@ -106,7 +106,7 @@ EFI_STATUS efivar_get_str16(const EFI_GUID *vendor, const char16_t *name, char16
         val = xmalloc(size + sizeof(char16_t));
 
         memcpy(val, buf, size);
-        val[size / sizeof(char16_t) - 1] = 0; /* NUL terminate */
+        val[size / sizeof(char16_t)] = 0; /* NUL terminate */
 
         *ret = val;
         return EFI_SUCCESS;