]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
efivars: properly NUL terminate EFI variables when reading
authorLennart Poettering <lennart@poettering.net>
Mon, 16 Dec 2019 11:07:06 +0000 (12:07 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 16 Dec 2019 14:35:31 +0000 (15:35 +0100)
A follow-up for 35b9eb0a72b6254568a294f0ebd011da20958a64.

src/basic/efivars.c

index bfde67a883b9fb7e56791ae0dcbcd28b2a3b806e..ea43abd7b3f63ca7d8342197ae4c20276df45270 100644 (file)
@@ -93,8 +93,8 @@ int efi_get_variable(
                 assert(n <= st.st_size - 4);
 
                 /* Always NUL terminate (2 bytes, to protect UTF-16) */
-                ((char*) buf)[n - 4] = 0;
-                ((char*) buf)[n - 4 + 1] = 0;
+                ((char*) buf)[n] = 0;
+                ((char*) buf)[n + 1] = 0;
         } else
                 /* Assume that the reported size is accurate */
                 n = st.st_size - 4;