From patchwork Fri Apr 25 07:44:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 342668 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 86AE0140163 for ; Fri, 25 Apr 2014 17:45:16 +1000 (EST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1Wdaoi-0000i0-0Q; Fri, 25 Apr 2014 07:45:04 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1Wdaob-0000hb-VH for fwts-devel@lists.ubuntu.com; Fri, 25 Apr 2014 07:44:57 +0000 Received: from [175.41.48.77] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1Wdaob-0004sl-CH; Fri, 25 Apr 2014 07:44:57 +0000 From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH] uefi: uefirtvariable: fix the fail GUID checking for uniqueness of variable (LP: #1311822) Date: Fri, 25 Apr 2014 15:44:51 +0800 Message-Id: <1398411891-26363-1-git-send-email-ivan.hu@canonical.com> X-Mailer: git-send-email 1.7.9.5 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com 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 Acked-by: Colin Ian King Acked-by: Alex Hung --- 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; }