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

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