[PATCH] uefi: uefirtvariable: fix the fail GUID checking for uniqueness of variable (LP: #1311822)

Ivan Hu ivan.hu at canonical.com
Fri Apr 25 07:44:51 UTC 2014


While using a simple hash bucket algorithm to check the uniqueness of each
variable and error if we encounter any duplicates, it used the same memory
address for GUID checking in each buckets. It makes the GUID would be identical,
so the result will be unexpected.

Signed-off-by: Ivan Hu <ivan.hu at canonical.com>
---
 src/uefi/uefirtvariable/uefirtvariable.c |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/uefi/uefirtvariable/uefirtvariable.c b/src/uefi/uefirtvariable/uefirtvariable.c
index 4b32693..5d31ad8 100644
--- a/src/uefi/uefirtvariable/uefirtvariable.c
+++ b/src/uefi/uefirtvariable/uefirtvariable.c
@@ -520,6 +520,7 @@ static void bucket_destroy(void)
 			struct efi_var_item *chain = item->next;
 
 			free(item->name);
+			free(item->guid);
 			free(item);
 			item = chain;
 		}
@@ -574,14 +575,24 @@ static int getnextvariable_test3(fwts_framework *fw)
 			goto err;
 		}
 
-		item->guid = &vendorguid;
-		item->next = NULL;
+		item->guid = malloc(sizeof(EFI_GUID));
+		if (!item->guid) {
+			fwts_failed(fw, LOG_LEVEL_HIGH,
+				"UEFIRuntimeGetNextVariableName",
+				"Failed to allocate memory for test.");
+			free(item);
+			goto err;
+		}
 
+		memcpy(item->guid, &vendorguid, sizeof(EFI_GUID));
+
+		item->next = NULL;
 		item->name = malloc(variablenamesize);
 		if (!item->name) {
 			fwts_failed(fw, LOG_LEVEL_HIGH,
 				"UEFIRuntimeGetNextVariableName",
 				"Failed to allocate memory for test.");
+			free(item->guid);
 			free(item);
 			goto err;
 		}
@@ -596,6 +607,7 @@ static int getnextvariable_test3(fwts_framework *fw)
 				"UEFIRuntimeGetNextVariableName",
 				"Duplicate variable name found.");
 			free(item->name);
+			free(item->guid);
 			free(item);
 			goto err;
 		}
-- 
1.7.9.5




More information about the fwts-devel mailing list