Blame SOURCES/0009-tpm2_eventlog_yaml-use-defines-for-Unicode-variables.patch

c8bd4f
From e05d4ac57960b9aa81943254f5757405a5217616 Mon Sep 17 00:00:00 2001
c8bd4f
From: Thore Sommer <mail@thson.de>
c8bd4f
Date: Tue, 11 Oct 2022 08:44:44 +0300
c8bd4f
Subject: [PATCH 9/9] tpm2_eventlog_yaml: use defines for Unicode variables
c8bd4f
c8bd4f
The used variables and their length are defined as the following:
c8bd4f
c8bd4f
 - Name: NAME_{VARIABLE_NAME}
c8bd4f
 - Length: NAME_{VARIABLE_NAME}_LEN
c8bd4f
c8bd4f
Signed-off-by: Thore Sommer <mail@thson.de>
c8bd4f
---
c8bd4f
 lib/tpm2_eventlog_yaml.c | 30 +++++++++++++++++++++++-------
c8bd4f
 1 file changed, 23 insertions(+), 7 deletions(-)
c8bd4f
c8bd4f
diff --git a/lib/tpm2_eventlog_yaml.c b/lib/tpm2_eventlog_yaml.c
c8bd4f
index 0b1d0318..59a5d8fc 100644
c8bd4f
--- a/lib/tpm2_eventlog_yaml.c
c8bd4f
+++ b/lib/tpm2_eventlog_yaml.c
c8bd4f
@@ -23,6 +23,22 @@
c8bd4f
 #include <efivar/efivar.h>
c8bd4f
 #endif
c8bd4f
 
c8bd4f
+/* Valid variable unicode names and their length */
c8bd4f
+#define NAME_DB "db"
c8bd4f
+#define NAME_DB_LEN 2
c8bd4f
+#define NAME_DBX "dbx"
c8bd4f
+#define NAME_DBX_LEN 3
c8bd4f
+#define NAME_KEK "KEK"
c8bd4f
+#define NAME_KEK_LEN 3
c8bd4f
+#define NAME_PK "PK"
c8bd4f
+#define NAME_PK_LEN 2
c8bd4f
+#define NAME_MOKLISTTRUSTED "MokListTrusted"
c8bd4f
+#define NAME_MOKLISTTRUSTED_LEN 14
c8bd4f
+#define NAME_SECUREBOOT "SecureBoot"
c8bd4f
+#define NAME_SECUREBOOT_LEN 10
c8bd4f
+#define NAME_BOOTORDER "BootOrder"
c8bd4f
+#define NAME_BOOTORDER_LEN 9
c8bd4f
+
c8bd4f
 static void guid_unparse_lower(EFI_GUID guid, char guid_buf[37]) {
c8bd4f
 
c8bd4f
     snprintf(guid_buf, 37, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
c8bd4f
@@ -321,10 +337,10 @@ static bool yaml_uefi_var(UEFI_VARIABLE_DATA *data, size_t size, UINT32 type,
c8bd4f
          * respectively.
c8bd4f
          */
c8bd4f
         if (type == EV_EFI_VARIABLE_DRIVER_CONFIG) {
c8bd4f
-            if ((strlen(ret) == 2 && strncmp(ret, "PK", 2) == 0) ||
c8bd4f
-                (strlen(ret) == 3 && strncmp(ret, "KEK", 3) == 0) ||
c8bd4f
-                (strlen(ret) == 2 && strncmp(ret, "db", 2) == 0) ||
c8bd4f
-                (strlen(ret) == 3 && strncmp(ret, "dbx", 3) == 0)) {
c8bd4f
+            if ((strlen(ret) == NAME_PK_LEN && strncmp(ret, NAME_PK, NAME_PK_LEN) == 0) ||
c8bd4f
+                (strlen(ret) == NAME_KEK_LEN && strncmp(ret, NAME_KEK, NAME_KEK_LEN) == 0) ||
c8bd4f
+                (strlen(ret) == NAME_DB_LEN && strncmp(ret, NAME_DB, NAME_DB_LEN) == 0) ||
c8bd4f
+                (strlen(ret) == NAME_DBX_LEN && strncmp(ret, NAME_DBX, NAME_DBX_LEN) == 0)) {
c8bd4f
 
c8bd4f
                 free(ret);
c8bd4f
                 tpm2_tool_output("    VariableData:\n");
c8bd4f
@@ -397,7 +413,7 @@ static bool yaml_uefi_var(UEFI_VARIABLE_DATA *data, size_t size, UINT32 type,
c8bd4f
                     variable_data += slist->SignatureListSize;
c8bd4f
                 }
c8bd4f
                 return true;
c8bd4f
-            } else if ((strlen(ret) == 10 && strncmp(ret, "SecureBoot", 10) == 0)) {
c8bd4f
+            } else if ((strlen(ret) == NAME_SECUREBOOT_LEN && strncmp(ret, NAME_SECUREBOOT, NAME_SECUREBOOT_LEN) == 0)) {
c8bd4f
                 free(ret);
c8bd4f
                 tpm2_tool_output("    VariableData:\n"
c8bd4f
                                  "      Enabled: ");
c8bd4f
@@ -420,7 +436,7 @@ static bool yaml_uefi_var(UEFI_VARIABLE_DATA *data, size_t size, UINT32 type,
c8bd4f
             }
c8bd4f
         } else if (type == EV_EFI_VARIABLE_AUTHORITY) {
c8bd4f
             /* The MokListTrusted is boolean option, not a EFI_SIGNATURE_DATA*/
c8bd4f
-            if ((strlen(ret) == 14 && strncmp(ret, "MokListTrusted", 14) == 0)) {
c8bd4f
+            if ((strlen(ret) == NAME_MOKLISTTRUSTED_LEN && strncmp(ret, NAME_MOKLISTTRUSTED, NAME_MOKLISTTRUSTED_LEN) == 0)) {
c8bd4f
                 free(ret);
c8bd4f
                 tpm2_tool_output("    VariableData:\n"
c8bd4f
                                  "      Enabled: ");
c8bd4f
@@ -462,7 +478,7 @@ static bool yaml_uefi_var(UEFI_VARIABLE_DATA *data, size_t size, UINT32 type,
c8bd4f
                 return true;
c8bd4f
             }
c8bd4f
         } else if (type == EV_EFI_VARIABLE_BOOT || type == EV_EFI_VARIABLE_BOOT2) {
c8bd4f
-            if ((strlen(ret) == 9 && strncmp(ret, "BootOrder", 9) == 0)) {
c8bd4f
+            if ((strlen(ret) == NAME_BOOTORDER_LEN && strncmp(ret, NAME_BOOTORDER, NAME_BOOTORDER_LEN) == 0)) {
c8bd4f
                 free(ret);
c8bd4f
                 tpm2_tool_output("    VariableData:\n");
c8bd4f
                 
c8bd4f
-- 
c8bd4f
2.37.3
c8bd4f