From d83399e08656dc8c951caf60b7043846cb9539cd Mon Sep 17 00:00:00 2001 From: Star Zeng Date: Wed, 15 Jun 2016 13:38:03 +0800 Subject: NetworkPkg: Replace UnicodeStrToAsciiStr/AsciiStrToUnicodeStr It is the follow up of 3ab41b7a325ca11a12b42f5ad1661c4b6791cb49 to replace UnicodeStrToAsciiStr/AsciiStrToUnicodeStr with UnicodeStrToAsciiStrS/AsciiStrToUnicodeStrS. Cc: Jiewen Yao Cc: Siyuan Fu Cc: Jiaxin Wu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng Reviewed-by: Jaben Carsey Reviewed-by: Jiaxin Wu Reviewed-by: Siyuan Fu (cherry picked from commit b9679cd7458110573dd4614148433312b61a1e26) --- .../Application/IpsecConfig/PolicyEntryOperation.c | 6 +- NetworkPkg/HttpBootDxe/HttpBootClient.c | 19 +++-- NetworkPkg/HttpDxe/HttpImpl.c | 8 +- NetworkPkg/HttpDxe/HttpProto.c | 8 +- NetworkPkg/IScsiDxe/IScsiConfig.c | 88 +++++++++++++++------- NetworkPkg/IScsiDxe/IScsiDriver.c | 2 +- NetworkPkg/IScsiDxe/IScsiMisc.c | 6 +- 7 files changed, 86 insertions(+), 51 deletions(-) diff --git a/NetworkPkg/Application/IpsecConfig/PolicyEntryOperation.c b/NetworkPkg/Application/IpsecConfig/PolicyEntryOperation.c index 970caa16ca..6af9a4a547 100644 --- a/NetworkPkg/Application/IpsecConfig/PolicyEntryOperation.c +++ b/NetworkPkg/Application/IpsecConfig/PolicyEntryOperation.c @@ -271,7 +271,7 @@ CreateSpdEntry ( // ValueStr = ShellCommandLineGetValue (ParamPackage, L"--name"); if (ValueStr != NULL) { - UnicodeStrToAsciiStr (ValueStr, (CHAR8 *) (*Data)->Name); + UnicodeStrToAsciiStrS (ValueStr, (CHAR8 *) (*Data)->Name, sizeof ((*Data)->Name)); *Mask |= NAME; } @@ -785,7 +785,7 @@ CreateSadEntry ( (*Data)->AlgoInfo.EspAlgoInfo.EncKeyLength = EncKeyLength; AsciiStr = AllocateZeroPool (EncKeyLength + 1); ASSERT (AsciiStr != NULL); - UnicodeStrToAsciiStr (ValueStr, AsciiStr); + UnicodeStrToAsciiStrS (ValueStr, AsciiStr, EncKeyLength + 1); CopyMem ((*Data)->AlgoInfo.EspAlgoInfo.EncKey, AsciiStr, EncKeyLength); FreePool (AsciiStr); *Mask |= ENCRYPT_KEY; @@ -815,7 +815,7 @@ CreateSadEntry ( (*Data)->AlgoInfo.EspAlgoInfo.AuthKeyLength = AuthKeyLength; AsciiStr = AllocateZeroPool (AuthKeyLength + 1); ASSERT (AsciiStr != NULL); - UnicodeStrToAsciiStr (ValueStr, AsciiStr); + UnicodeStrToAsciiStrS (ValueStr, AsciiStr, AuthKeyLength + 1); CopyMem ((*Data)->AlgoInfo.EspAlgoInfo.AuthKey, AsciiStr, AuthKeyLength); FreePool (AsciiStr); *Mask |= AUTH_KEY; diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c b/NetworkPkg/HttpBootDxe/HttpBootClient.c index f0817e92e2..319fefbbbd 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootClient.c +++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c @@ -244,6 +244,7 @@ HttpBootDhcp6ExtractUriInfo ( EFI_DHCP6_PACKET_OPTION *Option; EFI_IPv6_ADDRESS IpAddr; CHAR8 *HostName; + UINTN HostNameSize; CHAR16 *HostNameStr; EFI_STATUS Status; @@ -313,14 +314,15 @@ HttpBootDhcp6ExtractUriInfo ( if (EFI_ERROR (Status)) { return Status; } - - HostNameStr = AllocateZeroPool ((AsciiStrLen (HostName) + 1) * sizeof (CHAR16)); + + HostNameSize = AsciiStrSize (HostName); + HostNameStr = AllocateZeroPool (HostNameSize * sizeof (CHAR16)); if (HostNameStr == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Error; } - AsciiStrToUnicodeStr (HostName, HostNameStr); + AsciiStrToUnicodeStrS (HostName, HostNameStr, HostNameSize); Status = HttpBootDns (Private, HostNameStr, &IpAddr); FreePool (HostNameStr); if (EFI_ERROR (Status)) { @@ -728,6 +730,7 @@ HttpBootGetBootFile ( UINTN ContentLength; HTTP_BOOT_CACHE_CONTENT *Cache; UINT8 *Block; + UINTN UrlSize; CHAR16 *Url; BOOLEAN IdentityMode; UINTN ReceivedSize; @@ -746,11 +749,12 @@ HttpBootGetBootFile ( // // First, check whether we already cached the requested Uri. // - Url = AllocatePool ((AsciiStrLen (Private->BootFileUri) + 1) * sizeof (CHAR16)); + UrlSize = AsciiStrSize (Private->BootFileUri); + Url = AllocatePool (UrlSize * sizeof (CHAR16)); if (Url == NULL) { return EFI_OUT_OF_RESOURCES; } - AsciiStrToUnicodeStr (Private->BootFileUri, Url); + AsciiStrToUnicodeStrS (Private->BootFileUri, Url, UrlSize); if (!HeaderOnly) { Status = HttpBootGetFileFromCache (Private, Url, BufferSize, Buffer); if (Status != EFI_NOT_FOUND) { @@ -848,11 +852,6 @@ HttpBootGetBootFile ( } RequestData->Method = HeaderOnly ? HttpMethodHead : HttpMethodGet; RequestData->Url = Url; - if (RequestData->Url == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto ERROR_4; - } - AsciiStrToUnicodeStr (Private->BootFileUri, RequestData->Url); // // 2.3 Record the request info in a temp cache item. diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c index aee3de517f..db50b5b1cc 100644 --- a/NetworkPkg/HttpDxe/HttpImpl.c +++ b/NetworkPkg/HttpDxe/HttpImpl.c @@ -235,6 +235,7 @@ EfiHttpRequest ( VOID *UrlParser; EFI_STATUS Status; CHAR8 *HostName; + UINTN HostNameSize; UINT16 RemotePort; HTTP_PROTOCOL *HttpInstance; BOOLEAN Configure; @@ -306,7 +307,7 @@ EfiHttpRequest ( } - UnicodeStrToAsciiStr (Request->Url, Url); + UnicodeStrToAsciiStrS (Request->Url, Url, UrlLen); UrlParser = NULL; Status = HttpParseUrl (Url, (UINT32) AsciiStrLen (Url), FALSE, &UrlParser); if (EFI_ERROR (Status)) { @@ -405,13 +406,14 @@ EfiHttpRequest ( } if (EFI_ERROR (Status)) { - HostNameStr = AllocateZeroPool ((AsciiStrLen (HostName) + 1) * sizeof (CHAR16)); + HostNameSize = AsciiStrSize (HostName); + HostNameStr = AllocateZeroPool (HostNameSize * sizeof (CHAR16)); if (HostNameStr == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Error1; } - AsciiStrToUnicodeStr (HostName, HostNameStr); + AsciiStrToUnicodeStrS (HostName, HostNameStr, HostNameSize); if (!HttpInstance->LocalAddressIsIPv6) { Status = HttpDns4 (HttpInstance, HostNameStr, &HttpInstance->RemoteAddr); } else { diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c index 9660b6fb67..4315ed494f 100644 --- a/NetworkPkg/HttpDxe/HttpProto.c +++ b/NetworkPkg/HttpDxe/HttpProto.c @@ -1,7 +1,7 @@ /** @file Miscellaneous routines for HttpDxe driver. -Copyright (c) 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -1565,6 +1565,7 @@ HttpTcpTransmit ( EFI_STATUS Status; CHAR8 *RequestStr; CHAR8 *Url; + UINTN UrlSize; ValueInItem = (HTTP_TOKEN_WRAP *) Item->Value; if (ValueInItem->TcpWrap.IsTxDone) { @@ -1574,12 +1575,13 @@ HttpTcpTransmit ( // // Parse the URI of the remote host. // - Url = AllocatePool (StrLen (ValueInItem->HttpToken->Message->Data.Request->Url) + 1); + UrlSize = StrLen (ValueInItem->HttpToken->Message->Data.Request->Url) + 1; + Url = AllocatePool (UrlSize); if (Url == NULL) { return EFI_OUT_OF_RESOURCES; } - UnicodeStrToAsciiStr (ValueInItem->HttpToken->Message->Data.Request->Url, Url); + UnicodeStrToAsciiStrS (ValueInItem->HttpToken->Message->Data.Request->Url, Url, UrlSize); // // Create request message. diff --git a/NetworkPkg/IScsiDxe/IScsiConfig.c b/NetworkPkg/IScsiDxe/IScsiConfig.c index 69a400389d..a82ce231e8 100644 --- a/NetworkPkg/IScsiDxe/IScsiConfig.c +++ b/NetworkPkg/IScsiDxe/IScsiConfig.c @@ -1,7 +1,7 @@ /** @file Helper functions for configuring or getting the parameters relating to iSCSI. -Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -390,7 +390,11 @@ IScsiConvertAttemptConfigDataToIfrNvData ( IScsiIpToStr (&Ip, TRUE, IfrNvData->TargetIp); } - AsciiStrToUnicodeStr (SessionConfigData->TargetName, IfrNvData->TargetName); + AsciiStrToUnicodeStrS ( + SessionConfigData->TargetName, + IfrNvData->TargetName, + sizeof (IfrNvData->TargetName) / sizeof (IfrNvData->TargetName[0]) + ); IScsiLunToUnicodeStr (SessionConfigData->BootLun, IfrNvData->BootLun); IScsiConvertIsIdToString (IfrNvData->IsId, SessionConfigData->IsId); @@ -405,16 +409,36 @@ IScsiConvertAttemptConfigDataToIfrNvData ( if (IfrNvData->AuthenticationType == ISCSI_AUTH_TYPE_CHAP) { AuthConfigData = &Attempt->AuthConfigData.CHAP; IfrNvData->CHAPType = AuthConfigData->CHAPType; - AsciiStrToUnicodeStr (AuthConfigData->CHAPName, IfrNvData->CHAPName); - AsciiStrToUnicodeStr (AuthConfigData->CHAPSecret, IfrNvData->CHAPSecret); - AsciiStrToUnicodeStr (AuthConfigData->ReverseCHAPName, IfrNvData->ReverseCHAPName); - AsciiStrToUnicodeStr (AuthConfigData->ReverseCHAPSecret, IfrNvData->ReverseCHAPSecret); + AsciiStrToUnicodeStrS ( + AuthConfigData->CHAPName, + IfrNvData->CHAPName, + sizeof (IfrNvData->CHAPName) / sizeof (IfrNvData->CHAPName[0]) + ); + AsciiStrToUnicodeStrS ( + AuthConfigData->CHAPSecret, + IfrNvData->CHAPSecret, + sizeof (IfrNvData->CHAPSecret) / sizeof (IfrNvData->CHAPSecret[0]) + ); + AsciiStrToUnicodeStrS ( + AuthConfigData->ReverseCHAPName, + IfrNvData->ReverseCHAPName, + sizeof (IfrNvData->ReverseCHAPName) / sizeof (IfrNvData->ReverseCHAPName[0]) + ); + AsciiStrToUnicodeStrS ( + AuthConfigData->ReverseCHAPSecret, + IfrNvData->ReverseCHAPSecret, + sizeof (IfrNvData->ReverseCHAPSecret) / sizeof (IfrNvData->ReverseCHAPSecret[0]) + ); } // // Other parameters. // - AsciiStrToUnicodeStr (Attempt->AttemptName, IfrNvData->AttemptName); + AsciiStrToUnicodeStrS ( + Attempt->AttemptName, + IfrNvData->AttemptName, + sizeof (IfrNvData->AttemptName) / sizeof (IfrNvData->AttemptName[0]) + ); } /** @@ -603,12 +627,12 @@ IScsiConvertIfrNvDataToAttemptConfigData ( return EFI_OUT_OF_RESOURCES; } - AsciiStrToUnicodeStr (Attempt->AttemptName, AttemptName1); + AsciiStrToUnicodeStrS (Attempt->AttemptName, AttemptName1, ATTEMPT_NAME_MAX_SIZE); if (StrLen (AttemptName1) > ATTEMPT_NAME_SIZE) { CopyMem (&AttemptName1[ATTEMPT_NAME_SIZE], L"...", 4 * sizeof (CHAR16)); } - AsciiStrToUnicodeStr (SameNicAttempt->AttemptName, AttemptName2); + AsciiStrToUnicodeStrS (SameNicAttempt->AttemptName, AttemptName2, ATTEMPT_NAME_MAX_SIZE); if (StrLen (AttemptName2) > ATTEMPT_NAME_SIZE) { CopyMem (&AttemptName2[ATTEMPT_NAME_SIZE], L"...", 4 * sizeof (CHAR16)); } @@ -663,7 +687,7 @@ IScsiConvertIfrNvDataToAttemptConfigData ( return EFI_OUT_OF_RESOURCES; } - AsciiStrToUnicodeStr (Attempt->MacString, MacString); + AsciiStrToUnicodeStrS (Attempt->MacString, MacString, sizeof (MacString) / sizeof (MacString[0])); UnicodeSPrint ( mPrivate->PortString, @@ -1087,7 +1111,7 @@ IScsiConfigUpdateAttempt ( NET_LIST_FOR_EACH (Entry, &mPrivate->AttemptConfigs) { AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link); - AsciiStrToUnicodeStr (AttemptConfigData->AttemptName, AttemptName); + AsciiStrToUnicodeStrS (AttemptConfigData->AttemptName, AttemptName, sizeof (AttemptName) / sizeof (AttemptName[0])); UnicodeSPrint (mPrivate->PortString, (UINTN) 128, L"Attempt %s", AttemptName); AttemptConfigData->AttemptTitleToken = HiiSetString ( mCallbackInfo->RegisteredHandle, @@ -1216,7 +1240,7 @@ IScsiConfigDeleteAttempts ( mPrivate->SinglePathCount--; } - AsciiStrToUnicodeStr (AttemptConfigData->MacString, MacString); + AsciiStrToUnicodeStrS (AttemptConfigData->MacString, MacString, sizeof (MacString) / sizeof (MacString[0])); UnicodeSPrint ( mPrivate->PortString, @@ -1730,7 +1754,7 @@ IScsiConfigProcessDefault ( MacString ); - UnicodeStrToAsciiStr (MacString, AttemptConfigData->MacString); + UnicodeStrToAsciiStrS (MacString, AttemptConfigData->MacString, sizeof (AttemptConfigData->MacString)); AttemptConfigData->NicIndex = NicIndex; // @@ -1773,7 +1797,7 @@ IScsiConfigProcessDefault ( L"%d", (UINTN) AttemptConfigData->AttemptConfigIndex ); - UnicodeStrToAsciiStr (mPrivate->PortString, AttemptConfigData->AttemptName); + UnicodeStrToAsciiStrS (mPrivate->PortString, AttemptConfigData->AttemptName, sizeof (AttemptConfigData->AttemptName)); // // Save the created Attempt temporarily. If user does not save the attempt @@ -1942,7 +1966,11 @@ IScsiFormExtractConfig ( if (EFI_ERROR (Status)) { IfrNvData->InitiatorName[0] = L'\0'; } else { - AsciiStrToUnicodeStr (InitiatorName, IfrNvData->InitiatorName); + AsciiStrToUnicodeStrS ( + InitiatorName, + IfrNvData->InitiatorName, + sizeof (IfrNvData->InitiatorName) / sizeof (IfrNvData->InitiatorName[0]) + ); } // @@ -2210,7 +2238,7 @@ IScsiFormCallback ( } else if (Action == EFI_BROWSER_ACTION_CHANGED) { switch (QuestionId) { case KEY_INITIATOR_NAME: - UnicodeStrToAsciiStr (IfrNvData->InitiatorName, IScsiName); + UnicodeStrToAsciiStrS (IfrNvData->InitiatorName, IScsiName, ISCSI_NAME_MAX_SIZE); BufferSize = AsciiStrSize (IScsiName); Status = gIScsiInitiatorName.Set (&gIScsiInitiatorName, &BufferSize, IScsiName); @@ -2237,7 +2265,7 @@ IScsiFormCallback ( ); } - UnicodeStrToAsciiStr (IfrNvData->AttemptName, Private->Current->AttemptName); + UnicodeStrToAsciiStrS (IfrNvData->AttemptName, Private->Current->AttemptName, sizeof (Private->Current->AttemptName)); IScsiConfigUpdateAttempt (); @@ -2366,7 +2394,7 @@ IScsiFormCallback ( break; case KEY_TARGET_IP: - UnicodeStrToAsciiStr (IfrNvData->TargetIp, IpString); + UnicodeStrToAsciiStrS (IfrNvData->TargetIp, IpString, sizeof (IpString)); Status = IScsiAsciiStrToIp (IpString, IfrNvData->IpMode, &HostIp); if (EFI_ERROR (Status) || !IpIsUnicast (&HostIp, IfrNvData->IpMode)) { CreatePopUp ( @@ -2383,7 +2411,7 @@ IScsiFormCallback ( break; case KEY_TARGET_NAME: - UnicodeStrToAsciiStr (IfrNvData->TargetName, IScsiName); + UnicodeStrToAsciiStrS (IfrNvData->TargetName, IScsiName, ISCSI_NAME_MAX_SIZE); Status = IScsiNormalizeName (IScsiName, AsciiStrLen (IScsiName)); if (EFI_ERROR (Status)) { CreatePopUp ( @@ -2406,7 +2434,7 @@ IScsiFormCallback ( break; case KEY_BOOT_LUN: - UnicodeStrToAsciiStr (IfrNvData->BootLun, LunString); + UnicodeStrToAsciiStrS (IfrNvData->BootLun, LunString, sizeof (LunString)); Status = IScsiAsciiStrToLun (LunString, (UINT8 *) &Lun); if (EFI_ERROR (Status)) { CreatePopUp ( @@ -2433,30 +2461,34 @@ IScsiFormCallback ( break; case KEY_CHAP_NAME: - UnicodeStrToAsciiStr ( + UnicodeStrToAsciiStrS ( IfrNvData->CHAPName, - Private->Current->AuthConfigData.CHAP.CHAPName + Private->Current->AuthConfigData.CHAP.CHAPName, + sizeof (Private->Current->AuthConfigData.CHAP.CHAPName) ); break; case KEY_CHAP_SECRET: - UnicodeStrToAsciiStr ( + UnicodeStrToAsciiStrS ( IfrNvData->CHAPSecret, - Private->Current->AuthConfigData.CHAP.CHAPSecret + Private->Current->AuthConfigData.CHAP.CHAPSecret, + sizeof (Private->Current->AuthConfigData.CHAP.CHAPSecret) ); break; case KEY_REVERSE_CHAP_NAME: - UnicodeStrToAsciiStr ( + UnicodeStrToAsciiStrS ( IfrNvData->ReverseCHAPName, - Private->Current->AuthConfigData.CHAP.ReverseCHAPName + Private->Current->AuthConfigData.CHAP.ReverseCHAPName, + sizeof (Private->Current->AuthConfigData.CHAP.ReverseCHAPName) ); break; case KEY_REVERSE_CHAP_SECRET: - UnicodeStrToAsciiStr ( + UnicodeStrToAsciiStrS ( IfrNvData->ReverseCHAPSecret, - Private->Current->AuthConfigData.CHAP.ReverseCHAPSecret + Private->Current->AuthConfigData.CHAP.ReverseCHAPSecret, + sizeof (Private->Current->AuthConfigData.CHAP.ReverseCHAPSecret) ); break; diff --git a/NetworkPkg/IScsiDxe/IScsiDriver.c b/NetworkPkg/IScsiDxe/IScsiDriver.c index 363daadc8f..0d9406e727 100644 --- a/NetworkPkg/IScsiDxe/IScsiDriver.c +++ b/NetworkPkg/IScsiDxe/IScsiDriver.c @@ -515,7 +515,7 @@ IScsiStart ( Session->ConfigData = AttemptConfigData; Session->AuthType = AttemptConfigData->AuthenticationType; - AsciiStrToUnicodeStr (AttemptConfigData->MacString, MacString); + AsciiStrToUnicodeStrS (AttemptConfigData->MacString, MacString, sizeof (MacString) / sizeof (MacString[0])); UnicodeSPrint ( mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, diff --git a/NetworkPkg/IScsiDxe/IScsiMisc.c b/NetworkPkg/IScsiDxe/IScsiMisc.c index e7198d5ab0..be8f1532bf 100644 --- a/NetworkPkg/IScsiDxe/IScsiMisc.c +++ b/NetworkPkg/IScsiDxe/IScsiMisc.c @@ -1095,7 +1095,7 @@ IScsiGetConfigData ( // // Refresh the state of this attempt to NVR. // - AsciiStrToUnicodeStr (AttemptTmp->MacString, MacString); + AsciiStrToUnicodeStrS (AttemptTmp->MacString, MacString, sizeof (MacString) / sizeof (MacString[0])); UnicodeSPrint ( mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, @@ -1134,7 +1134,7 @@ IScsiGetConfigData ( // // Refresh the state of this attempt to NVR. // - AsciiStrToUnicodeStr (AttemptTmp->MacString, MacString); + AsciiStrToUnicodeStrS (AttemptTmp->MacString, MacString, sizeof (MacString) / sizeof (MacString[0])); UnicodeSPrint ( mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, @@ -1225,7 +1225,7 @@ IScsiGetConfigData ( // // Refresh the state of this attempt to NVR. // - AsciiStrToUnicodeStr (AttemptConfigData->MacString, MacString); + AsciiStrToUnicodeStrS (AttemptConfigData->MacString, MacString, sizeof (MacString) / sizeof (MacString[0])); UnicodeSPrint ( mPrivate->PortString, (UINTN) ISCSI_NAME_IFR_MAX_SIZE, -- cgit v1.2.3