From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 CB17D202E60E9 for ; Wed, 18 Oct 2017 00:02:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A0F2C047B8C; Wed, 18 Oct 2017 07:05:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0A0F2C047B8C Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-113.rdu2.redhat.com [10.10.120.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id C728D17273; Wed, 18 Oct 2017 07:05:52 +0000 (UTC) To: chenc2 , edk2-devel@lists.01.org Cc: Wu Hao , Zhang Chao References: <20171018045001.16012-1-chen.a.chen@intel.com> From: Laszlo Ersek Message-ID: Date: Wed, 18 Oct 2017 09:05:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171018045001.16012-1-chen.a.chen@intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 18 Oct 2017 07:05:54 +0000 (UTC) Subject: Re: [PATCH] SecurityPkg/SecureBootConfigDxe: Add check to avoid X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Oct 2017 07:02:18 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Hi, On 10/18/17 06:50, chenc2 wrote: > The function HiiGetString will return NULL pointer when > the platform does not install the appropriate string or > call HiiGetString fail.(For example, HII not support specified > language.) > > Cc: Zhang Chao > Cc: Wu Hao > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: chenc2 > --- > .../SecureBootConfigDxe/SecureBootConfigImpl.c | 97 +++++++++++++++------- > 1 file changed, 66 insertions(+), 31 deletions(-) The subject line of this patch appears truncated. Thanks Laszlo > diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c > index acb0dc0558..4ce5172701 100644 > --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c > +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.c > @@ -3572,6 +3572,9 @@ LoadSignatureList ( > { > EFI_STATUS Status; > EFI_STRING_ID ListType; > + EFI_STRING FormatNameString; > + EFI_STRING FormatHelpString; > + EFI_STRING FormatTypeString; > EFI_SIGNATURE_LIST *ListWalker; > EFI_IFR_GUID_LABEL *StartLabel; > EFI_IFR_GUID_LABEL *EndLabel; > @@ -3705,6 +3708,12 @@ LoadSignatureList ( > goto ON_EXIT; > } > > + FormatNameString = HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_LIST_NAME_FORMAT), NULL); > + FormatHelpString = HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_LIST_HELP_FORMAT), NULL); > + if (FormatNameString == NULL || FormatHelpString == NULL) { > + goto ON_EXIT; > + } > + > RemainingSize = DataSize; > ListWalker = (EFI_SIGNATURE_LIST *)VariableData; > while ((RemainingSize > 0) && (RemainingSize >= ListWalker->SignatureListSize)) { > @@ -3725,21 +3734,23 @@ LoadSignatureList ( > } else { > ListType = STRING_TOKEN (STR_LIST_TYPE_UNKNOWN); > } > + FormatTypeString = HiiGetString (PrivateData->HiiHandle, ListType, NULL); > + if (FormatTypeString == NULL) { > + goto ON_EXIT; > + } > > ZeroMem (NameBuffer, sizeof (NameBuffer)); > - UnicodeSPrint (NameBuffer, > - sizeof (NameBuffer), > - HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_LIST_NAME_FORMAT), NULL), > - Index + 1 > - ); > + UnicodeSPrint (NameBuffer, sizeof (NameBuffer), FormatNameString, Index + 1); > > ZeroMem (HelpBuffer, sizeof (HelpBuffer)); > UnicodeSPrint (HelpBuffer, > sizeof (HelpBuffer), > - HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_LIST_HELP_FORMAT), NULL), > - HiiGetString (PrivateData->HiiHandle, ListType, NULL), > + FormatHelpString, > + FormatTypeString, > SIGNATURE_DATA_COUNTS (ListWalker) > ); > + SECUREBOOT_FREE_NON_NULL (FormatTypeString); > + FormatTypeString = NULL; > > HiiCreateGotoOpCode ( > StartOpCodeHandle, > @@ -3777,6 +3788,8 @@ ON_EXIT: > SECUREBOOT_FREE_NON_OPCODE (EndGotoHandle); > > SECUREBOOT_FREE_NON_NULL (VariableData); > + SECUREBOOT_FREE_NON_NULL (FormatNameString); > + SECUREBOOT_FREE_NON_NULL (FormatHelpString); > > PrivateData->ListCount = Index; > > @@ -3922,6 +3935,8 @@ FormatHelpInfo ( > EFI_STATUS Status; > EFI_TIME *Time; > EFI_STRING_ID ListTypeId; > + EFI_STRING FormatHelpString; > + EFI_STRING FormatTypeString; > UINTN DataSize; > UINTN HelpInfoIndex; > UINTN TotalSize; > @@ -3969,6 +3984,11 @@ FormatHelpInfo ( > goto ON_EXIT; > } > > + FormatTypeString = HiiGetString (PrivateData->HiiHandle, ListTypeId, NULL); > + if (FormatTypeString == NULL) { > + goto ON_EXIT; > + } > + > TotalSize = 1024; > HelpInfoString = AllocateZeroPool (TotalSize); > if (HelpInfoString == NULL) { > @@ -3981,40 +4001,45 @@ FormatHelpInfo ( > // > ZeroMem (GuidString, sizeof (GuidString)); > GuidToString(&DataEntry->SignatureOwner, GuidString, BUFFER_MAX_SIZE); > + FormatHelpString = HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_DATA_HELP_FORMAT_GUID), NULL); > + if (FormatHelpString == NULL) { > + goto ON_EXIT; > + } > HelpInfoIndex += UnicodeSPrint ( > &HelpInfoString[HelpInfoIndex], > TotalSize - sizeof(CHAR16) * HelpInfoIndex, > - HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_DATA_HELP_FORMAT_GUID), NULL), > + FormatHelpString, > GuidString > ); > + SECUREBOOT_FREE_NON_NULL (FormatHelpString); > + FormatHelpString = NULL; > > // > // Format content part, it depends on the type of signature list, hash value or CN. > // > if (IsCert) { > GetCommonNameFromX509 (ListEntry, DataEntry, &DataString); > - HelpInfoIndex += UnicodeSPrint( > - &HelpInfoString[HelpInfoIndex], > - TotalSize - sizeof(CHAR16) * HelpInfoIndex, > - HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_DATA_HELP_FORMAT_CN), NULL), > - HiiGetString (PrivateData->HiiHandle, ListTypeId, NULL), > - DataSize, > - DataString > - ); > + FormatHelpString = HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_DATA_HELP_FORMAT_CN), NULL); > } else { > // > // Format hash value for each signature data entry. > // > ParseHashValue (ListEntry, DataEntry, &DataString); > - HelpInfoIndex += UnicodeSPrint ( > - &HelpInfoString[HelpInfoIndex], > - TotalSize - sizeof(CHAR16) * HelpInfoIndex, > - HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_DATA_HELP_FORMAT_HASH), NULL), > - HiiGetString (PrivateData->HiiHandle, ListTypeId, NULL), > - DataSize, > - DataString > - ); > + FormatHelpString = HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_DATA_HELP_FORMAT_HASH), NULL); > + } > + if (FormatHelpString == NULL) { > + goto ON_EXIT; > } > + HelpInfoIndex += UnicodeSPrint ( > + &HelpInfoString[HelpInfoIndex], > + TotalSize - sizeof (CHAR16) * HelpInfoIndex, > + FormatHelpString, > + FormatTypeString, > + DataSize, > + DataString > + ); > + SECUREBOOT_FREE_NON_NULL (FormatHelpString); > + FormatHelpString = NULL; > > // > // Format revocation time part. > @@ -4032,13 +4057,18 @@ FormatHelpInfo ( > Time->Minute, > Time->Second > ); > - > + FormatHelpString = HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_DATA_HELP_FORMAT_TIME), NULL); > + if (FormatHelpString == NULL) { > + goto ON_EXIT; > + } > UnicodeSPrint ( > &HelpInfoString[HelpInfoIndex], > TotalSize - sizeof (CHAR16) * HelpInfoIndex, > - HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_DATA_HELP_FORMAT_TIME), NULL), > + FormatHelpString, > TimeString > ); > + SECUREBOOT_FREE_NON_NULL (FormatHelpString); > + FormatHelpString = NULL; > } > > *StringId = HiiSetString (PrivateData->HiiHandle, 0, HelpInfoString, NULL); > @@ -4046,6 +4076,8 @@ ON_EXIT: > SECUREBOOT_FREE_NON_NULL (DataString); > SECUREBOOT_FREE_NON_NULL (HelpInfoString); > > + SECUREBOOT_FREE_NON_NULL (FormatTypeString); > + > return Status; > } > > @@ -4076,6 +4108,7 @@ LoadSignatureData ( > EFI_IFR_GUID_LABEL *StartLabel; > EFI_IFR_GUID_LABEL *EndLabel; > EFI_STRING_ID HelpStringId; > + EFI_STRING FormatNameString; > VOID *StartOpCodeHandle; > VOID *EndOpCodeHandle; > UINTN DataSize; > @@ -4167,17 +4200,18 @@ LoadSignatureData ( > ListWalker = (EFI_SIGNATURE_LIST *)((UINT8 *)ListWalker + ListWalker->SignatureListSize); > } > > + FormatNameString = HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_DATA_NAME_FORMAT), NULL); > + if (FormatNameString == NULL) { > + goto ON_EXIT; > + } > + > DataWalker = (EFI_SIGNATURE_DATA *)((UINT8 *)ListWalker + sizeof(EFI_SIGNATURE_LIST) + ListWalker->SignatureHeaderSize); > for (Index = 0; Index < SIGNATURE_DATA_COUNTS(ListWalker); Index = Index + 1) { > // > // Format name buffer. > // > ZeroMem (NameBuffer, sizeof (NameBuffer)); > - UnicodeSPrint (NameBuffer, > - sizeof (NameBuffer), > - HiiGetString (PrivateData->HiiHandle, STRING_TOKEN (STR_SIGNATURE_DATA_NAME_FORMAT), NULL), > - Index + 1 > - ); > + UnicodeSPrint (NameBuffer, sizeof (NameBuffer), FormatNameString, Index + 1); > > // > // Format help info buffer. > @@ -4221,6 +4255,7 @@ ON_EXIT: > SECUREBOOT_FREE_NON_OPCODE (EndOpCodeHandle); > > SECUREBOOT_FREE_NON_NULL (VariableData); > + SECUREBOOT_FREE_NON_NULL (FormatNameString); > > return Status; > } >