grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v4 1/2] luks, luks2: Force header.uuid to be NULL terminated


From: Glenn Washburn
Subject: [PATCH v4 1/2] luks, luks2: Force header.uuid to be NULL terminated
Date: Fri, 22 Jul 2022 02:43:13 -0500

According to the LUKS specification the uuid header field is of data type
"char[]", which is defined as "a string stored as null terminated sequence
of 8-bit characters". So enforce this by adding a null byte as the last byte
of the uuid. The LUKS2 specification defers to the LUKS1 specification in
this regard.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
 grub-core/disk/luks.c  | 3 +++
 grub-core/disk/luks2.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c
index 7f837d52c..ad72e5d1f 100644
--- a/grub-core/disk/luks.c
+++ b/grub-core/disk/luks.c
@@ -87,6 +87,9 @@ luks_scan (grub_disk_t disk, grub_cryptomount_args_t cargs)
       return NULL;
     }
 
+  /* According to the spec the uuid field is NULL terminated, so enforce it. */
+  header.uuid[sizeof (header.uuid) - 1] = '\0';
+
   /* Look for LUKS magic sequence.  */
   if (grub_memcmp (header.magic, LUKS_MAGIC, sizeof (header.magic))
       || grub_be_to_cpu16 (header.version) != 1)
diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c
index bf741d70f..1346c3821 100644
--- a/grub-core/disk/luks2.c
+++ b/grub-core/disk/luks2.c
@@ -342,6 +342,9 @@ luks2_read_header (grub_disk_t disk, grub_luks2_header_t 
*outhdr)
       header = &secondary;
   grub_memcpy (outhdr, header, sizeof (*header));
 
+  /* According to the spec the uuid field is NULL terminated, so enforce it. */
+  header->uuid[sizeof (header->uuid) - 1] = '\0';
+
   return GRUB_ERR_NONE;
 }
 
-- 
2.34.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]