From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2266281C57 for ; Sun, 20 Nov 2016 17:49:46 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP; 20 Nov 2016 17:49:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,524,1473145200"; d="scan'208";a="33824303" Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.135]) by fmsmga006.fm.intel.com with ESMTP; 20 Nov 2016 17:49:45 -0800 From: Dandan Bi To: edk2-devel@lists.01.org Cc: Jiewen Yao Date: Mon, 21 Nov 2016 09:49:01 +0800 Message-Id: <1479692941-68464-1-git-send-email-dandan.bi@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Subject: [PATCH v2] MdeModulePkg/DxeCapsuleLibFmp: Use AllocatePool for CapsuleResultVariable X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Nov 2016 01:49:46 -0000 V2: Add check for the result of AllocatePool function. Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Dandan Bi --- .../Library/DxeCapsuleLibFmp/DxeCapsuleReportLib.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleReportLib.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleReportLib.c index a0ed2d0..2546871 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleReportLib.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleReportLib.c @@ -289,36 +289,44 @@ RecordFmpCapsuleStatusVariable ( IN EFI_STATUS CapsuleStatus, IN UINTN PayloadIndex, IN EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *ImageHeader ) { - UINT8 CapsuleResultVariable[sizeof(EFI_CAPSULE_RESULT_VARIABLE_HEADER) + sizeof(EFI_CAPSULE_RESULT_VARIABLE_FMP)]; EFI_CAPSULE_RESULT_VARIABLE_HEADER *CapsuleResultVariableHeader; EFI_CAPSULE_RESULT_VARIABLE_FMP *CapsuleResultVariableFmp; EFI_STATUS Status; + UINT8 *CapsuleResultVariable; + UINT32 CapsuleResultVariableSize; - CapsuleResultVariableHeader = (VOID *)&CapsuleResultVariable[0]; - CapsuleResultVariableHeader->VariableTotalSize = sizeof(CapsuleResultVariable); + CapsuleResultVariable = NULL; + CapsuleResultVariableSize = sizeof(EFI_CAPSULE_RESULT_VARIABLE_HEADER) + sizeof(EFI_CAPSULE_RESULT_VARIABLE_FMP); + CapsuleResultVariable = AllocatePool (CapsuleResultVariableSize); + if (CapsuleResultVariable == NULL) { + return EFI_OUT_OF_RESOURCES; + } + CapsuleResultVariableHeader = (VOID *)CapsuleResultVariable; + CapsuleResultVariableHeader->VariableTotalSize = CapsuleResultVariableSize; CopyGuid(&CapsuleResultVariableHeader->CapsuleGuid, &CapsuleHeader->CapsuleGuid); ZeroMem(&CapsuleResultVariableHeader->CapsuleProcessed, sizeof(CapsuleResultVariableHeader->CapsuleProcessed)); gRT->GetTime(&CapsuleResultVariableHeader->CapsuleProcessed, NULL); CapsuleResultVariableHeader->CapsuleStatus = CapsuleStatus; - CapsuleResultVariableFmp = (VOID *)&CapsuleResultVariable[sizeof(EFI_CAPSULE_RESULT_VARIABLE_HEADER)]; + CapsuleResultVariableFmp = (VOID *)(CapsuleResultVariable + sizeof(EFI_CAPSULE_RESULT_VARIABLE_HEADER)); CapsuleResultVariableFmp->Version = 0x1; CapsuleResultVariableFmp->PayloadIndex = (UINT8)PayloadIndex; CapsuleResultVariableFmp->UpdateImageIndex = ImageHeader->UpdateImageIndex; CopyGuid (&CapsuleResultVariableFmp->UpdateImageTypeId, &ImageHeader->UpdateImageTypeId); // // Save Local Cache // - Status = WriteNewCapsuleResultVariableCache(&CapsuleResultVariable, sizeof(CapsuleResultVariable)); + Status = WriteNewCapsuleResultVariableCache(CapsuleResultVariable, CapsuleResultVariableSize); if ((CapsuleHeader->Flags & CAPSULE_FLAGS_PERSIST_ACROSS_RESET) != 0) { - Status = WriteNewCapsuleResultVariable(&CapsuleResultVariable, sizeof(CapsuleResultVariable)); + Status = WriteNewCapsuleResultVariable(CapsuleResultVariable, CapsuleResultVariableSize); } + FreePool (CapsuleResultVariable); return Status; } /** Initialize CapsuleMax variables. -- 1.9.5.msysgit.1