From nobody Sat Nov 2 14:36:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487739055187866.842581262587; Tue, 21 Feb 2017 20:50:55 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A903D8222D; Tue, 21 Feb 2017 20:50:52 -0800 (PST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 ADA848221C for ; Tue, 21 Feb 2017 20:50:51 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2017 20:50:51 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga001.jf.intel.com with ESMTP; 21 Feb 2017 20:50:50 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,192,1484035200"; d="scan'208";a="1100867134" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 22 Feb 2017 12:50:37 +0800 Message-Id: <20170222045047.558308-2-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20170222045047.558308-1-ruiyu.ni@intel.com> References: <20170222045047.558308-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 01/11] MdePkg: Define IPv4_ADDRESS and IPv6_ADDRESS in Base.h 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: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since the following patch needs to add API converting string to IP address in BaseLib, define the IP address as base types in Base.h. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Liming Gao --- MdePkg/Include/Base.h | 16 +++++++++++++++- MdePkg/Include/Uefi/UefiBaseType.h | 10 +++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h index 8f5b919..5b311f6 100644 --- a/MdePkg/Include/Base.h +++ b/MdePkg/Include/Base.h @@ -6,7 +6,7 @@ environment. There are a set of base libraries in the Mde Package that c= an be used to implement base modules. =20 -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD = License @@ -265,6 +265,20 @@ typedef struct { UINT8 Data4[8]; } GUID; =20 +/// +/// 4-byte buffer. An IPv4 internet protocol address. +/// +typedef struct { + UINT8 Addr[4]; +} IPv4_ADDRESS; + +/// +/// 16-byte buffer. An IPv6 internet protocol address. +/// +typedef struct { + UINT8 Addr[16]; +} IPv6_ADDRESS; + // // 8-bytes unsigned value that represents a physical system address. // diff --git a/MdePkg/Include/Uefi/UefiBaseType.h b/MdePkg/Include/Uefi/UefiB= aseType.h index 84e4dc6..728a047 100644 --- a/MdePkg/Include/Uefi/UefiBaseType.h +++ b/MdePkg/Include/Uefi/UefiBaseType.h @@ -1,7 +1,7 @@ /** @file Defines data types and constants introduced in UEFI. =20 -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
Portions copyright (c) 2011 - 2016, ARM Ltd. All rights reserved.
=20 This program and the accompanying materials are licensed and made availabl= e under=20 @@ -87,16 +87,12 @@ typedef struct { /// /// 4-byte buffer. An IPv4 internet protocol address. /// -typedef struct { - UINT8 Addr[4]; -} EFI_IPv4_ADDRESS; +typedef IPv4_ADDRESS EFI_IPv4_ADDRESS; =20 /// /// 16-byte buffer. An IPv6 internet protocol address. /// -typedef struct { - UINT8 Addr[16]; -} EFI_IPv6_ADDRESS; +typedef IPv6_ADDRESS EFI_IPv6_ADDRESS; =20 /// /// 32-byte buffer containing a network Media Access Control address. --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 14:36:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487739057638518.6253235551839; Tue, 21 Feb 2017 20:50:57 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EF5E08222A; Tue, 21 Feb 2017 20:50:54 -0800 (PST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 A4A0082228 for ; Tue, 21 Feb 2017 20:50:52 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2017 20:50:52 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga001.jf.intel.com with ESMTP; 21 Feb 2017 20:50:51 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,192,1484035200"; d="scan'208";a="1100867137" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 22 Feb 2017 12:50:38 +0800 Message-Id: <20170222045047.558308-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20170222045047.558308-1-ruiyu.ni@intel.com> References: <20170222045047.558308-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 02/11] MdePkg/UefiDevicePathLib: Rename StrToGuid to avoid link failure 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: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since the next patch will add StrToGuid in BaseLib, renaming the internal function StrToGuid to DevicePathLibStrToGuid to avoid link failure. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Liming Gao --- MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c | 18 +++++++++------= --- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c b/MdePkg= /Library/UefiDevicePathLib/DevicePathFromText.c index 8a3a470..e2b06a2 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c @@ -1,7 +1,7 @@ /** @file DevicePathFromText protocol as defined in the UEFI 2.0 specification. =20 -Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2013 - 2017, 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 @@ -397,7 +397,7 @@ StrToBuf ( =20 **/ EFI_STATUS -StrToGuid ( +DevicePathLibStrToGuid ( IN CHAR16 *Str, OUT EFI_GUID *Guid ) @@ -740,7 +740,7 @@ ConvertFromTextVendor ( (UINT16) (sizeof (VENDOR_DEVICE_PATH)= + Length) ); =20 - StrToGuid (GuidStr, &Vendor->Guid); + DevicePathLibStrToGuid (GuidStr, &Vendor->Guid); StrToBuf (((UINT8 *) Vendor) + sizeof (VENDOR_DEVICE_PATH), Length, Data= Str); =20 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor; @@ -1453,7 +1453,7 @@ DevPathFromTextInfiniband ( ); =20 InfiniBand->ResourceFlags =3D (UINT32) Strtoi (FlagsStr); - StrToGuid (GuidStr, &PortGid); + DevicePathLibStrToGuid (GuidStr, &PortGid); CopyMem (InfiniBand->PortGid, &PortGid, sizeof (EFI_GUID)); Strtoi64 (SidStr, &InfiniBand->ServiceId); Strtoi64 (TidStr, &InfiniBand->TargetPortId); @@ -2976,7 +2976,7 @@ DevPathFromTextHD ( Hd->SignatureType =3D SIGNATURE_TYPE_GUID; Hd->MBRType =3D 0x02; =20 - StrToGuid (SignatureStr, &SignatureGuid); + DevicePathLibStrToGuid (SignatureStr, &SignatureGuid); CopyMem (Hd->Signature, &SignatureGuid, sizeof (EFI_GUID)); } else { Hd->SignatureType =3D (UINT8) Strtoi (TypeStr); @@ -3091,7 +3091,7 @@ DevPathFromTextMedia ( (UINT16) sizeof (MEDIA_PROTOC= OL_DEVICE_PATH) ); =20 - StrToGuid (GuidStr, &Media->Protocol); + DevicePathLibStrToGuid (GuidStr, &Media->Protocol); =20 return (EFI_DEVICE_PATH_PROTOCOL *) Media; } @@ -3119,7 +3119,7 @@ DevPathFromTextFv ( (UINT16) sizeof (MEDIA_FW_VOL_D= EVICE_PATH) ); =20 - StrToGuid (GuidStr, &Fv->FvName); + DevicePathLibStrToGuid (GuidStr, &Fv->FvName); =20 return (EFI_DEVICE_PATH_PROTOCOL *) Fv; } @@ -3147,7 +3147,7 @@ DevPathFromTextFvFile ( (UINT16) sizeof (MEDIA= _FW_VOL_FILEPATH_DEVICE_PATH) ); =20 - StrToGuid (GuidStr, &FvFile->FvFileName); + DevicePathLibStrToGuid (GuidStr, &FvFile->FvFileName); =20 return (EFI_DEVICE_PATH_PROTOCOL *) FvFile; } @@ -3219,7 +3219,7 @@ DevPathFromTextRamDisk ( Strtoi64 (EndingAddrStr, &EndingAddr); WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr); RamDisk->Instance =3D (UINT16) Strtoi (InstanceStr); - StrToGuid (TypeGuidStr, &RamDisk->TypeGuid); + DevicePathLibStrToGuid (TypeGuidStr, &RamDisk->TypeGuid); =20 return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk; } --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 14:36:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487739059965186.63202027412217; Tue, 21 Feb 2017 20:50:59 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3421382244; Tue, 21 Feb 2017 20:50:55 -0800 (PST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 9906182237 for ; Tue, 21 Feb 2017 20:50:53 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2017 20:50:53 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga001.jf.intel.com with ESMTP; 21 Feb 2017 20:50:52 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,192,1484035200"; d="scan'208";a="1100867140" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 22 Feb 2017 12:50:39 +0800 Message-Id: <20170222045047.558308-4-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20170222045047.558308-1-ruiyu.ni@intel.com> References: <20170222045047.558308-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 03/11] SignedCapsulePkg/IniParsing: Rename StrToGuid to avoid link failure 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: , Cc: Jiewen Yao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since the next patch will add AsciiStrToGuid in BaseLib, renaming the internal function AsciiStrToGuid to IniAsciiStrToGuid to avoid link failure. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Jiewen Yao --- SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.c b/Signe= dCapsulePkg/Library/IniParsingLib/IniParsingLib.c index 270380e..16e1349 100644 --- a/SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.c +++ b/SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.c @@ -25,7 +25,7 @@ OpenIniFile(), PreProcessDataFile(), ProfileGetSection(), ProfileGetEntr= y() will receive untrusted input and do basic validation. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
=20 This program and the accompanying materials are licensed and made available under the terms and conditions @@ -933,7 +933,7 @@ AsciiStrToBuf ( =20 **/ EFI_STATUS -AsciiStrToGuid ( +IniAsciiStrToGuid ( IN CHAR8 *Str, OUT EFI_GUID *Guid ) @@ -1261,7 +1261,7 @@ GetGuidFromDataFile ( if (!IsValidGuid(Value, AsciiStrLen(Value))) { return EFI_NOT_FOUND; } - Status =3D AsciiStrToGuid(Value, Guid); + Status =3D IniAsciiStrToGuid(Value, Guid); if (EFI_ERROR (Status)) { return EFI_NOT_FOUND; } --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 14:36:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487739063214978.7877230990952; Tue, 21 Feb 2017 20:51:03 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 75E3F82248; Tue, 21 Feb 2017 20:50:57 -0800 (PST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 F2FBE82237 for ; Tue, 21 Feb 2017 20:50:54 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2017 20:50:54 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga001.jf.intel.com with ESMTP; 21 Feb 2017 20:50:53 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,192,1484035200"; d="scan'208";a="1100867146" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 22 Feb 2017 12:50:40 +0800 Message-Id: <20170222045047.558308-5-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20170222045047.558308-1-ruiyu.ni@intel.com> References: <20170222045047.558308-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 04/11] MdePkg/BaseLib: Add StrToGuid/StrHexToBytes/StrToIpv[4/6]Address 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: , Cc: Siyuan Fu , Jiewen Yao , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The patch adds 4 APIs to convert Unicode string to GUID, bytes buffer, IP v4 address and IP v6 address. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Liming Gao Cc: Jiewen Yao Cc: Siyuan Fu --- MdePkg/Include/Library/BaseLib.h | 241 ++++++++++++++ MdePkg/Library/BaseLib/SafeString.c | 623 ++++++++++++++++++++++++++++++++= ++++ 2 files changed, 864 insertions(+) diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index d71ccb7..8aac4c8 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -1536,6 +1536,247 @@ StrHexToUint64 ( IN CONST CHAR16 *String ); =20 +/** + Convert a Null-terminated Unicode string to IPv6 address and prefix leng= th. + + This function outputs a value of type IPv6_ADDRESS and may output a value + of type UINT8 by interpreting the contents of the Unicode string specifi= ed + by String. The format of the input Unicode string String is as follows: + + X:X:X:X:X:X:X:X[/P] + + X contains one to four hexadecimal digit characters in the range [0-9], = [a-f] and + [A-F]. X is converted to a value of type UINT16, whose low byte is store= d in low + memory address and high byte is stored in high memory address. P contain= s decimal + digit characters in the range [0-9]. The running zero in the beginning o= f P will + be ignored. /P is optional. + + When /P is not in the String, the function stops at the first character = that is + not a valid hexadecimal digit character after eight X's are converted. + + When /P is in the String, the function stops at the first character that= is not + a valid decimal digit character after P is converted. + + "::" can be used to compress one or more groups of X when X contains onl= y 0. + The "::" can only appear once in the String. + + If String is NULL, then ASSERT(). + + If Address is NULL, then ASSERT(). + + If String is not aligned in a 16-bit boundary, then ASSERT(). + + If PcdMaximumUnicodeStringLength is not zero, and String contains more t= han + PcdMaximumUnicodeStringLength Unicode characters, not including the + Null-terminator, then ASSERT(). + + If EndPointer is not NULL and Address is translated from String, a point= er + to the character that stopped the scan is stored at the location pointed= to + by EndPointer. + + @param String Pointer to a Null-terminated Unicode st= ring. + @param EndPointer Pointer to character that stops scan. + @param Address Pointer to the converted IPv6 address. + @param PrefixLength Pointer to the converted IPv6 address p= refix + length. MAX_UINT8 is returned when /P is + not in the String. + + @retval RETURN_SUCCESS Address is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If PcdMaximumUnicodeStringLength is not + zero, and String contains more than + PcdMaximumUnicodeStringLength Unicode + characters, not including the + Null-terminator. + If X contains more than four hexadecimal + digit characters. + If String contains "::" and number of X + is not less than 8. + If P starts with character that is not a + valid decimal digit character. + If the decimal number converted from P + exceeds 128. + +**/ +RETURN_STATUS +EFIAPI +StrToIpv6Address ( + IN CONST CHAR16 *String, + OUT CHAR16 **EndPointer, OPTIONAL + OUT IPv6_ADDRESS *Address, + OUT UINT8 *PrefixLength OPTIONAL + ); + +/** + Convert a Null-terminated Unicode string to IPv4 address and prefix leng= th. + + This function outputs a value of type IPv4_ADDRESS and may output a value + of type UINT8 by interpreting the contents of the Unicode string specifi= ed + by String. The format of the input Unicode string String is as follows: + + D.D.D.D[/P] + + D and P are decimal digit characters in the range [0-9]. The running zer= o in + the beginning of D and P will be ignored. /P is optional. + + When /P is not in the String, the function stops at the first character = that is + not a valid decimal digit character after four D's are converted. + + When /P is in the String, the function stops at the first character that= is not + a valid decimal digit character after P is converted. + + If String is NULL, then ASSERT(). + + If Address is NULL, then ASSERT(). + + If String is not aligned in a 16-bit boundary, then ASSERT(). + + If PcdMaximumUnicodeStringLength is not zero, and String contains more t= han + PcdMaximumUnicodeStringLength Unicode characters, not including the + Null-terminator, then ASSERT(). + + If EndPointer is not NULL and Address is translated from String, a point= er + to the character that stopped the scan is stored at the location pointed= to + by EndPointer. + + @param String Pointer to a Null-terminated Unicode st= ring. + @param EndPointer Pointer to character that stops scan. + @param Address Pointer to the converted IPv4 address. + @param PrefixLength Pointer to the converted IPv4 address p= refix + length. MAX_UINT8 is returned when /P is + not in the String. + + @retval RETURN_SUCCESS Address is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If PcdMaximumUnicodeStringLength is not + zero, and String contains more than + PcdMaximumUnicodeStringLength Unicode + characters, not including the + Null-terminator. + If String is not in the correct format. + If any decimal number converted from D + exceeds 255. + If the decimal number converted from P + exceeds 32. + +**/ +RETURN_STATUS +EFIAPI +StrToIpv4Address ( + IN CONST CHAR16 *String, + OUT CHAR16 **EndPointer, OPTIONAL + OUT IPv4_ADDRESS *Address, + OUT UINT8 *PrefixLength OPTIONAL + ); + +#define GUID_STRING_LENGTH 36 + +/** + Convert a Null-terminated Unicode GUID string to a value of type + EFI_GUID. + + This function outputs a GUID value by interpreting the contents of + the Unicode string specified by String. The format of the input + Unicode string String consists of 36 characters, as follows: + + aabbccdd-eeff-gghh-iijj-kkllmmnnoopp + + The pairs aa - pp are two characters in the range [0-9], [a-f] and + [A-F], with each pair representing a single byte hexadecimal value. + + The mapping between String and the EFI_GUID structure is as follows: + aa Data1[24:31] + bb Data1[16:23] + cc Data1[8:15] + dd Data1[0:7] + ee Data2[8:15] + ff Data2[0:7] + gg Data3[8:15] + hh Data3[0:7] + ii Data4[0:7] + jj Data4[8:15] + kk Data4[16:23] + ll Data4[24:31] + mm Data4[32:39] + nn Data4[40:47] + oo Data4[48:55] + pp Data4[56:63] + + If String is NULL, then ASSERT(). + If Guid is NULL, then ASSERT(). + If String is not aligned in a 16-bit boundary, then ASSERT(). + + @param String Pointer to a Null-terminated Unicode st= ring. + @param Guid Pointer to the converted GUID. + + @retval RETURN_SUCCESS Guid is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If String is not as the above format. + +**/ +RETURN_STATUS +EFIAPI +StrToGuid ( + IN CONST CHAR16 *String, + OUT GUID *Guid + ); + +/** + Convert a Null-terminated Unicode hexadecimal string to a byte array. + + This function outputs a byte array by interpreting the contents of + the Unicode string specified by String in hexadecimal format. The format= of + the input Unicode string String is: + + [XX]* + + X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F]. + The function decodes every two hexadecimal digit characters as one byte.= The + decoding stops after Length of characters and outputs Buffer containing + (Length / 2) bytes. + + If String is not aligned in a 16-bit boundary, then ASSERT(). + + If String is NULL, then ASSERT(). + + If Buffer is NULL, then ASSERT(). + + If Length is not multiple of 2, then ASSERT(). + + If PcdMaximumStringLength is not zero and Length is greater than + PcdMaximumAsciiStringLength, then ASSERT(). + + If MaxBufferSize is less than (Length / 2), then ASSERT(). + + @param String Pointer to a Null-terminated Unicode st= ring. + @param Length The number of Unicode characters to dec= ode. + @param Buffer Pointer to the converted bytes array. + @param MaxBufferSize The maximum size of Buffer. + + @retval RETURN_SUCCESS Buffer is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If Length is not multiple of 2. + If PcdMaximumStringLength is not zero, + and Length is greater than + PcdMaximumAsciiStringLength. + If Length of characters from String con= tain + a character that is not valid hexadeci= mal + digit characters, or a Null-terminator. + @retval RETURN_BUFFER_TOO_SMALL If MaxBufferSize is less than (Length /= 2). +**/ +RETURN_STATUS +EFIAPI +StrHexToBytes ( + IN CONST CHAR16 *String, + IN UINTN Length, + OUT UINT8 *Buffer, + IN UINTN MaxBufferSize + ); + #ifndef DISABLE_NEW_DEPRECATED_INTERFACES =20 /** diff --git a/MdePkg/Library/BaseLib/SafeString.c b/MdePkg/Library/BaseLib/S= afeString.c index 315059e..ede1c99 100644 --- a/MdePkg/Library/BaseLib/SafeString.c +++ b/MdePkg/Library/BaseLib/SafeString.c @@ -1074,6 +1074,629 @@ StrHexToUint64S ( } =20 /** + Convert a Null-terminated Unicode string to IPv6 address and prefix leng= th. + + This function outputs a value of type IPv6_ADDRESS and may output a value + of type UINT8 by interpreting the contents of the Unicode string specifi= ed + by String. The format of the input Unicode string String is as follows: + + X:X:X:X:X:X:X:X[/P] + + X contains one to four hexadecimal digit characters in the range [0-9], = [a-f] and + [A-F]. X is converted to a value of type UINT16, whose low byte is store= d in low + memory address and high byte is stored in high memory address. P contain= s decimal + digit characters in the range [0-9]. The running zero in the beginning o= f P will + be ignored. /P is optional. + + When /P is not in the String, the function stops at the first character = that is + not a valid hexadecimal digit character after eight X's are converted. + + When /P is in the String, the function stops at the first character that= is not + a valid decimal digit character after P is converted. + + "::" can be used to compress one or more groups of X when X contains onl= y 0. + The "::" can only appear once in the String. + + If String is NULL, then ASSERT(). + + If Address is NULL, then ASSERT(). + + If String is not aligned in a 16-bit boundary, then ASSERT(). + + If PcdMaximumUnicodeStringLength is not zero, and String contains more t= han + PcdMaximumUnicodeStringLength Unicode characters, not including the + Null-terminator, then ASSERT(). + + If EndPointer is not NULL and Address is translated from String, a point= er + to the character that stopped the scan is stored at the location pointed= to + by EndPointer. + + @param String Pointer to a Null-terminated Unicode st= ring. + @param EndPointer Pointer to character that stops scan. + @param Address Pointer to the converted IPv6 address. + @param PrefixLength Pointer to the converted IPv6 address p= refix + length. MAX_UINT8 is returned when /P is + not in the String. + + @retval RETURN_SUCCESS Address is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If PcdMaximumUnicodeStringLength is not + zero, and String contains more than + PcdMaximumUnicodeStringLength Unicode + characters, not including the + Null-terminator. + If X contains more than four hexadecimal + digit characters. + If String contains "::" and number of X + is not less than 8. + If P starts with character that is not a + valid decimal digit character. + If the decimal number converted from P + exceeds 128. + +**/ +RETURN_STATUS +EFIAPI +StrToIpv6Address ( + IN CONST CHAR16 *String, + OUT CHAR16 **EndPointer, OPTIONAL + OUT IPv6_ADDRESS *Address, + OUT UINT8 *PrefixLength OPTIONAL + ) +{ + RETURN_STATUS Status; + UINTN AddressIndex; + UINTN Uintn; + IPv6_ADDRESS LocalAddress; + UINT8 LocalPrefixLength; + CONST CHAR16 *Pointer; + CHAR16 *End; + UINTN CompressStart; + BOOLEAN ExpectPrefix; + + LocalPrefixLength =3D MAX_UINT8; + CompressStart =3D ARRAY_SIZE (Address->Addr); + ExpectPrefix =3D FALSE; + + ASSERT (((UINTN) String & BIT0) =3D=3D 0); + + // + // 1. None of String or Guid shall be a null pointer. + // + SAFE_STRING_CONSTRAINT_CHECK ((String !=3D NULL), RETURN_INVALID_PARAMET= ER); + SAFE_STRING_CONSTRAINT_CHECK ((Address !=3D NULL), RETURN_INVALID_PARAME= TER); + + for (Pointer =3D String, AddressIndex =3D 0; AddressIndex < ARRAY_SIZE (= Address->Addr) + 1;) { + if (!InternalIsHexaDecimalDigitCharacter (*Pointer)) { + if (*Pointer !=3D L':') { + // + // ":" or "/" should be followed by digit characters. + // + return RETURN_INVALID_PARAMETER; + } + + // + // Meet second ":" after previous ":" or "/" + // or meet first ":" in the beginning of String. + // + if (ExpectPrefix) { + // + // ":" shall not be after "/" + // + return RETURN_INVALID_PARAMETER; + } + + if (CompressStart !=3D ARRAY_SIZE (Address->Addr) || AddressIndex = =3D=3D ARRAY_SIZE (Address->Addr)) { + // + // "::" can only appear once. + // "::" can only appear when address is not full length. + // + return RETURN_INVALID_PARAMETER; + } else { + // + // Remember the start of zero compressing. + // + CompressStart =3D AddressIndex; + Pointer++; + + if (CompressStart =3D=3D 0) { + if (*Pointer !=3D L':') { + // + // Single ":" shall not be in the beginning of String. + // + return RETURN_INVALID_PARAMETER; + } + Pointer++; + } + } + } + + if (!InternalIsHexaDecimalDigitCharacter (*Pointer)) { + if (*Pointer =3D=3D L'/') { + // + // Might be optional "/P" after "::". + // + if (CompressStart !=3D AddressIndex) { + return RETURN_INVALID_PARAMETER; + } + } else { + break; + } + } else { + if (!ExpectPrefix) { + // + // Get X. + // + Status =3D StrHexToUintnS (Pointer, &End, &Uintn); + if (RETURN_ERROR (Status) || End - Pointer > 4) { + // + // Number of hexadecimal digit characters is no more than 4. + // + return RETURN_INVALID_PARAMETER; + } + Pointer =3D End; + // + // Uintn won't exceed MAX_UINT16 if number of hexadecimal digit ch= aracters is no more than 4. + // + LocalAddress.Addr[AddressIndex] =3D (UINT8) ((UINT16) Uintn >> 8); + LocalAddress.Addr[AddressIndex + 1] =3D (UINT8) Uintn; + AddressIndex +=3D 2; + } else { + // + // Get P, then exit the loop. + // + Status =3D StrDecimalToUintnS (Pointer, &End, &Uintn); + if (RETURN_ERROR (Status) || End =3D=3D Pointer || Uintn > 128) { + // + // Prefix length should not exceed 128. + // + return RETURN_INVALID_PARAMETER; + } + LocalPrefixLength =3D (UINT8) Uintn; + Pointer =3D End; + break; + } + } + + // + // Skip ':' or "/" + // + if (*Pointer =3D=3D L'/') { + ExpectPrefix =3D TRUE; + } else if (*Pointer =3D=3D L':') { + if (AddressIndex =3D=3D ARRAY_SIZE (Address->Addr)) { + // + // Meet additional ":" after all 8 16-bit address + // + break; + } + } else { + // + // Meet other character that is not "/" or ":" after all 8 16-bit ad= dress + // + break; + } + Pointer++; + } + + if ((AddressIndex =3D=3D ARRAY_SIZE (Address->Addr) && CompressStart != =3D ARRAY_SIZE (Address->Addr)) || + (AddressIndex !=3D ARRAY_SIZE (Address->Addr) && CompressStart =3D=3D = ARRAY_SIZE (Address->Addr)) + ) { + // + // Full length of address shall not have compressing zeros. + // Non-full length of address shall have compressing zeros. + // + return RETURN_INVALID_PARAMETER; + } + CopyMem (&Address->Addr[0], &LocalAddress.Addr[0], CompressStart); + ZeroMem (&Address->Addr[CompressStart], ARRAY_SIZE (Address->Addr) - Add= ressIndex); + CopyMem ( + &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressInd= ex], + &LocalAddress.Addr[CompressStart], + AddressIndex - CompressStart + ); + + if (PrefixLength !=3D NULL) { + *PrefixLength =3D LocalPrefixLength; + } + if (EndPointer !=3D NULL) { + *EndPointer =3D (CHAR16 *) Pointer; + } + + return RETURN_SUCCESS; +} + +/** + Convert a Null-terminated Unicode string to IPv4 address and prefix leng= th. + + This function outputs a value of type IPv4_ADDRESS and may output a value + of type UINT8 by interpreting the contents of the Unicode string specifi= ed + by String. The format of the input Unicode string String is as follows: + + D.D.D.D[/P] + + D and P are decimal digit characters in the range [0-9]. The running zer= o in + the beginning of D and P will be ignored. /P is optional. + + When /P is not in the String, the function stops at the first character = that is + not a valid decimal digit character after four D's are converted. + + When /P is in the String, the function stops at the first character that= is not + a valid decimal digit character after P is converted. + + If String is NULL, then ASSERT(). + + If Address is NULL, then ASSERT(). + + If String is not aligned in a 16-bit boundary, then ASSERT(). + + If PcdMaximumUnicodeStringLength is not zero, and String contains more t= han + PcdMaximumUnicodeStringLength Unicode characters, not including the + Null-terminator, then ASSERT(). + + If EndPointer is not NULL and Address is translated from String, a point= er + to the character that stopped the scan is stored at the location pointed= to + by EndPointer. + + @param String Pointer to a Null-terminated Unicode st= ring. + @param EndPointer Pointer to character that stops scan. + @param Address Pointer to the converted IPv4 address. + @param PrefixLength Pointer to the converted IPv4 address p= refix + length. MAX_UINT8 is returned when /P is + not in the String. + + @retval RETURN_SUCCESS Address is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If PcdMaximumUnicodeStringLength is not + zero, and String contains more than + PcdMaximumUnicodeStringLength Unicode + characters, not including the + Null-terminator. + If String is not in the correct format. + If any decimal number converted from D + exceeds 255. + If the decimal number converted from P + exceeds 32. + +**/ +RETURN_STATUS +EFIAPI +StrToIpv4Address ( + IN CONST CHAR16 *String, + OUT CHAR16 **EndPointer, OPTIONAL + OUT IPv4_ADDRESS *Address, + OUT UINT8 *PrefixLength OPTIONAL + ) +{ + RETURN_STATUS Status; + UINTN AddressIndex; + UINTN Uintn; + IPv4_ADDRESS LocalAddress; + UINT8 LocalPrefixLength; + CHAR16 *Pointer; + + LocalPrefixLength =3D MAX_UINT8; + + ASSERT (((UINTN) String & BIT0) =3D=3D 0); + + // + // 1. None of String or Guid shall be a null pointer. + // + SAFE_STRING_CONSTRAINT_CHECK ((String !=3D NULL), RETURN_INVALID_PARAMET= ER); + SAFE_STRING_CONSTRAINT_CHECK ((Address !=3D NULL), RETURN_INVALID_PARAME= TER); + + for (Pointer =3D (CHAR16 *) String, AddressIndex =3D 0; AddressIndex < A= RRAY_SIZE (Address->Addr) + 1;) { + if (!InternalIsDecimalDigitCharacter (*Pointer)) { + // + // D or P contains invalid characters. + // + break; + } + + // + // Get D or P. + // + Status =3D StrDecimalToUintnS ((CONST CHAR16 *) Pointer, &Pointer, &Ui= ntn); + if (RETURN_ERROR (Status)) { + return RETURN_INVALID_PARAMETER; + } + if (AddressIndex =3D=3D ARRAY_SIZE (Address->Addr)) { + // + // It's P. + // + if (Uintn > 32) { + return RETURN_INVALID_PARAMETER; + } + LocalPrefixLength =3D (UINT8) Uintn; + } else { + // + // It's D. + // + if (Uintn > MAX_UINT8) { + return RETURN_INVALID_PARAMETER; + } + LocalAddress.Addr[AddressIndex] =3D (UINT8) Uintn; + AddressIndex++; + } + + // + // Check the '.' or '/', depending on the AddressIndex. + // + if (AddressIndex =3D=3D ARRAY_SIZE (Address->Addr)) { + if (*Pointer =3D=3D L'/') { + // + // '/P' is in the String. + // Skip "/" and get P in next loop. + // + Pointer++; + } else { + // + // '/P' is not in the String. + // + break; + } + } else if (AddressIndex < ARRAY_SIZE (Address->Addr)) { + if (*Pointer =3D=3D L'.') { + // + // D should be followed by '.' + // + Pointer++; + } else { + return RETURN_INVALID_PARAMETER; + } + } + } + + if (AddressIndex < ARRAY_SIZE (Address->Addr)) { + return RETURN_INVALID_PARAMETER; + } + + CopyMem (Address, &LocalAddress, sizeof (*Address)); + if (PrefixLength !=3D NULL) { + *PrefixLength =3D LocalPrefixLength; + } + if (EndPointer !=3D NULL) { + *EndPointer =3D Pointer; + } + + return RETURN_SUCCESS; +} + +/** + Convert a Null-terminated Unicode GUID string to a value of type + EFI_GUID. + + This function outputs a GUID value by interpreting the contents of + the Unicode string specified by String. The format of the input + Unicode string String consists of 36 characters, as follows: + + aabbccdd-eeff-gghh-iijj-kkllmmnnoopp + + The pairs aa - pp are two characters in the range [0-9], [a-f] and + [A-F], with each pair representing a single byte hexadecimal value. + + The mapping between String and the EFI_GUID structure is as follows: + aa Data1[24:31] + bb Data1[16:23] + cc Data1[8:15] + dd Data1[0:7] + ee Data2[8:15] + ff Data2[0:7] + gg Data3[8:15] + hh Data3[0:7] + ii Data4[0:7] + jj Data4[8:15] + kk Data4[16:23] + ll Data4[24:31] + mm Data4[32:39] + nn Data4[40:47] + oo Data4[48:55] + pp Data4[56:63] + + If String is NULL, then ASSERT(). + If Guid is NULL, then ASSERT(). + If String is not aligned in a 16-bit boundary, then ASSERT(). + + @param String Pointer to a Null-terminated Unicode st= ring. + @param Guid Pointer to the converted GUID. + + @retval RETURN_SUCCESS Guid is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If String is not as the above format. + +**/ +RETURN_STATUS +EFIAPI +StrToGuid ( + IN CONST CHAR16 *String, + OUT GUID *Guid + ) +{ + RETURN_STATUS Status; + GUID LocalGuid; + + ASSERT (((UINTN) String & BIT0) =3D=3D 0); + + // + // 1. None of String or Guid shall be a null pointer. + // + SAFE_STRING_CONSTRAINT_CHECK ((String !=3D NULL), RETURN_INVALID_PARAMET= ER); + SAFE_STRING_CONSTRAINT_CHECK ((Guid !=3D NULL), RETURN_INVALID_PARAMETER= ); + + // + // Get aabbccdd in big-endian. + // + Status =3D StrHexToBytes (String, 2 * sizeof (LocalGuid.Data1), (UINT8 *= ) &LocalGuid.Data1, sizeof (LocalGuid.Data1)); + if (RETURN_ERROR (Status) || String[2 * sizeof (LocalGuid.Data1)] !=3D L= '-') { + return RETURN_INVALID_PARAMETER; + } + // + // Convert big-endian to little-endian. + // + LocalGuid.Data1 =3D SwapBytes32 (LocalGuid.Data1); + String +=3D 2 * sizeof (LocalGuid.Data1) + 1; + + // + // Get eeff in big-endian. + // + Status =3D StrHexToBytes (String, 2 * sizeof (LocalGuid.Data2), (UINT8 *= ) &LocalGuid.Data2, sizeof (LocalGuid.Data2)); + if (RETURN_ERROR (Status) || String[2 * sizeof (LocalGuid.Data2)] !=3D L= '-') { + return RETURN_INVALID_PARAMETER; + } + // + // Convert big-endian to little-endian. + // + LocalGuid.Data2 =3D SwapBytes16 (LocalGuid.Data2); + String +=3D 2 * sizeof (LocalGuid.Data2) + 1; + + // + // Get gghh in big-endian. + // + Status =3D StrHexToBytes (String, 2 * sizeof (LocalGuid.Data3), (UINT8 *= ) &LocalGuid.Data3, sizeof (LocalGuid.Data3)); + if (RETURN_ERROR (Status) || String[2 * sizeof (LocalGuid.Data3)] !=3D L= '-') { + return RETURN_INVALID_PARAMETER; + } + // + // Convert big-endian to little-endian. + // + LocalGuid.Data3 =3D SwapBytes16 (LocalGuid.Data3); + String +=3D 2 * sizeof (LocalGuid.Data3) + 1; + + // + // Get iijj. + // + Status =3D StrHexToBytes (String, 2 * 2, &LocalGuid.Data4[0], 2); + if (RETURN_ERROR (Status) || String[2 * 2] !=3D L'-') { + return RETURN_INVALID_PARAMETER; + } + String +=3D 2 * 2 + 1; + + // + // Get kkllmmnnoopp. + // + Status =3D StrHexToBytes (String, 2 * 6, &LocalGuid.Data4[2], 6); + if (RETURN_ERROR (Status)) { + return RETURN_INVALID_PARAMETER; + } + + CopyGuid (Guid, &LocalGuid); + return RETURN_SUCCESS; +} + +/** + Convert a Null-terminated Unicode hexadecimal string to a byte array. + + This function outputs a byte array by interpreting the contents of + the Unicode string specified by String in hexadecimal format. The format= of + the input Unicode string String is: + + [XX]* + + X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F]. + The function decodes every two hexadecimal digit characters as one byte.= The + decoding stops after Length of characters and outputs Buffer containing + (Length / 2) bytes. + + If String is not aligned in a 16-bit boundary, then ASSERT(). + + If String is NULL, then ASSERT(). + + If Buffer is NULL, then ASSERT(). + + If Length is not multiple of 2, then ASSERT(). + + If PcdMaximumStringLength is not zero and Length is greater than + PcdMaximumAsciiStringLength, then ASSERT(). + + If MaxBufferSize is less than (Length / 2), then ASSERT(). + + @param String Pointer to a Null-terminated Unicode st= ring. + @param Length The number of Unicode characters to dec= ode. + @param Buffer Pointer to the converted bytes array. + @param MaxBufferSize The maximum size of Buffer. + + @retval RETURN_SUCCESS Buffer is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If Length is not multiple of 2. + If PcdMaximumStringLength is not zero, + and Length is greater than + PcdMaximumAsciiStringLength. + If Length of characters from String con= tain + a character that is not valid hexadeci= mal + digit characters, or a Null-terminator. + @retval RETURN_BUFFER_TOO_SMALL If MaxBufferSize is less than (Length /= 2). +**/ +RETURN_STATUS +EFIAPI +StrHexToBytes ( + IN CONST CHAR16 *String, + IN UINTN Length, + OUT UINT8 *Buffer, + IN UINTN MaxBufferSize + ) +{ + UINTN Index; + + ASSERT (((UINTN) String & BIT0) =3D=3D 0); + + // + // 1. None of String or Buffer shall be a null pointer. + // + SAFE_STRING_CONSTRAINT_CHECK ((String !=3D NULL), RETURN_INVALID_PARAMET= ER); + SAFE_STRING_CONSTRAINT_CHECK ((Buffer !=3D NULL), RETURN_INVALID_PARAMET= ER); + + // + // 2. Length shall not be greater than RSIZE_MAX. + // + if (RSIZE_MAX !=3D 0) { + SAFE_STRING_CONSTRAINT_CHECK ((Length <=3D RSIZE_MAX), RETURN_INVALID_= PARAMETER); + } + + // + // 3. Length shall not be odd. + // + SAFE_STRING_CONSTRAINT_CHECK (((Length & BIT0) =3D=3D 0), RETURN_INVALID= _PARAMETER); + + // + // 4. MaxBufferSize shall equal to or greater than Length / 2. + // + SAFE_STRING_CONSTRAINT_CHECK ((MaxBufferSize >=3D Length / 2), RETURN_BU= FFER_TOO_SMALL); + + // + // 5. String shall not contains invalid hexadecimal digits. + // + for (Index =3D 0; Index < Length; Index++) { + if (!InternalIsHexaDecimalDigitCharacter (String[Index])) { + break; + } + } + if (Index !=3D Length) { + return RETURN_INVALID_PARAMETER; + } + + // + // Convert the hex string to bytes. + // + for(Index =3D 0; Index < Length; Index++) { + + // + // For even characters, write the upper nibble for each buffer byte, + // and for even characters, the lower nibble. + // + if ((Index & BIT0) =3D=3D 0) { + Buffer[Index / 2] =3D (UINT8) InternalHexCharToUintn (String[Index]= ) << 4; + } else { + Buffer[Index / 2] |=3D (UINT8) InternalHexCharToUintn (String[Index]= ); + } + } + return RETURN_SUCCESS; +} + +/** Returns the length of a Null-terminated Ascii string. =20 This function is similar as strlen_s defined in C11. --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 14:36:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487739066239304.6221025423238; Tue, 21 Feb 2017 20:51:06 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AF0AB82253; Tue, 21 Feb 2017 20:50:57 -0800 (PST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 477A082248 for ; Tue, 21 Feb 2017 20:50:56 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2017 20:50:56 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga001.jf.intel.com with ESMTP; 21 Feb 2017 20:50:54 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,192,1484035200"; d="scan'208";a="1100867155" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 22 Feb 2017 12:50:41 +0800 Message-Id: <20170222045047.558308-6-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20170222045047.558308-1-ruiyu.ni@intel.com> References: <20170222045047.558308-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 05/11] MdePkg/BaseLib: Add AsciiStrToGuid/HexToBytes/ToIpv[4/6]Address 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: , Cc: Siyuan Fu , Jiewen Yao , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The patch adds 4 APIs to convert ASCII string to GUID, bytes buffer, IP v4 address and IP v6 address. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Liming Gao Cc: Jiewen Yao Cc: Siyuan Fu --- MdePkg/Include/Library/BaseLib.h | 214 +++++++++++++ MdePkg/Library/BaseLib/SafeString.c | 591 ++++++++++++++++++++++++++++++++= ++++ 2 files changed, 805 insertions(+) diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 8aac4c8..2f3614d 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -2428,6 +2428,220 @@ AsciiStrHexToUint64 ( IN CONST CHAR8 *String ); =20 +/** + Convert a Null-terminated ASCII string to IPv6 address and prefix length. + + This function outputs a value of type IPv6_ADDRESS and may output a value + of type UINT8 by interpreting the contents of the ASCII string specified + by String. The format of the input ASCII string String is as follows: + + X:X:X:X:X:X:X:X[/P] + + X contains one to four hexadecimal digit characters in the range [0-9], = [a-f] and + [A-F]. X is converted to a value of type UINT16, whose low byte is store= d in low + memory address and high byte is stored in high memory address. P contain= s decimal + digit characters in the range [0-9]. The running zero in the beginning o= f P will + be ignored. /P is optional. + + When /P is not in the String, the function stops at the first character = that is + not a valid hexadecimal digit character after eight X's are converted. + + When /P is in the String, the function stops at the first character that= is not + a valid decimal digit character after P is converted. + + "::" can be used to compress one or more groups of X when X contains onl= y 0. + The "::" can only appear once in the String. + + If String is NULL, then ASSERT(). + + If Address is NULL, then ASSERT(). + + If EndPointer is not NULL and Address is translated from String, a point= er + to the character that stopped the scan is stored at the location pointed= to + by EndPointer. + + @param String Pointer to a Null-terminated ASCII stri= ng. + @param EndPointer Pointer to character that stops scan. + @param Address Pointer to the converted IPv6 address. + @param PrefixLength Pointer to the converted IPv6 address p= refix + length. MAX_UINT8 is returned when /P is + not in the String. + + @retval RETURN_SUCCESS Address is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If X contains more than four hexadecimal + digit characters. + If String contains "::" and number of X + is not less than 8. + If P starts with character that is not a + valid decimal digit character. + If the decimal number converted from P + exceeds 128. + +**/ +RETURN_STATUS +EFIAPI +AsciiStrToIpv6Address ( + IN CONST CHAR8 *String, + OUT CHAR8 **EndPointer, OPTIONAL + OUT IPv6_ADDRESS *Address, + OUT UINT8 *PrefixLength OPTIONAL + ); + +/** + Convert a Null-terminated ASCII string to IPv4 address and prefix length. + + This function outputs a value of type IPv4_ADDRESS and may output a value + of type UINT8 by interpreting the contents of the ASCII string specified + by String. The format of the input ASCII string String is as follows: + + D.D.D.D[/P] + + D and P are decimal digit characters in the range [0-9]. The running zer= o in + the beginning of D and P will be ignored. /P is optional. + + When /P is not in the String, the function stops at the first character = that is + not a valid decimal digit character after four D's are converted. + + When /P is in the String, the function stops at the first character that= is not + a valid decimal digit character after P is converted. + + If String is NULL, then ASSERT(). + + If Address is NULL, then ASSERT(). + + If EndPointer is not NULL and Address is translated from String, a point= er + to the character that stopped the scan is stored at the location pointed= to + by EndPointer. + + @param String Pointer to a Null-terminated ASCII stri= ng. + @param EndPointer Pointer to character that stops scan. + @param Address Pointer to the converted IPv4 address. + @param PrefixLength Pointer to the converted IPv4 address p= refix + length. MAX_UINT8 is returned when /P is + not in the String. + + @retval RETURN_SUCCESS Address is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If String is not in the correct format. + If any decimal number converted from D + exceeds 255. + If the decimal number converted from P + exceeds 32. + +**/ +RETURN_STATUS +EFIAPI +AsciiStrToIpv4Address ( + IN CONST CHAR8 *String, + OUT CHAR8 **EndPointer, OPTIONAL + OUT IPv4_ADDRESS *Address, + OUT UINT8 *PrefixLength OPTIONAL + ); + +/** + Convert a Null-terminated ASCII GUID string to a value of type + EFI_GUID. + + This function outputs a GUID value by interpreting the contents of + the ASCII string specified by String. The format of the input + ASCII string String consists of 36 characters, as follows: + + aabbccdd-eeff-gghh-iijj-kkllmmnnoopp + + The pairs aa - pp are two characters in the range [0-9], [a-f] and + [A-F], with each pair representing a single byte hexadecimal value. + + The mapping between String and the EFI_GUID structure is as follows: + aa Data1[24:31] + bb Data1[16:23] + cc Data1[8:15] + dd Data1[0:7] + ee Data2[8:15] + ff Data2[0:7] + gg Data3[8:15] + hh Data3[0:7] + ii Data4[0:7] + jj Data4[8:15] + kk Data4[16:23] + ll Data4[24:31] + mm Data4[32:39] + nn Data4[40:47] + oo Data4[48:55] + pp Data4[56:63] + + If String is NULL, then ASSERT(). + If Guid is NULL, then ASSERT(). + + @param String Pointer to a Null-terminated ASCII stri= ng. + @param Guid Pointer to the converted GUID. + + @retval RETURN_SUCCESS Guid is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If String is not as the above format. + +**/ +RETURN_STATUS +EFIAPI +AsciiStrToGuid ( + IN CONST CHAR8 *String, + OUT GUID *Guid + ); + +/** + Convert a Null-terminated ASCII hexadecimal string to a byte array. + + This function outputs a byte array by interpreting the contents of + the ASCII string specified by String in hexadecimal format. The format of + the input ASCII string String is: + + [XX]* + + X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F]. + The function decodes every two hexadecimal digit characters as one byte.= The + decoding stops after Length of characters and outputs Buffer containing + (Length / 2) bytes. + + If String is NULL, then ASSERT(). + + If Buffer is NULL, then ASSERT(). + + If Length is not multiple of 2, then ASSERT(). + + If PcdMaximumAsciiStringLength is not zero and Length is greater than + PcdMaximumAsciiStringLength, then ASSERT(). + + If MaxBufferSize is less than (Length / 2), then ASSERT(). + + @param String Pointer to a Null-terminated ASCII stri= ng. + @param Length The number of ASCII characters to decod= e. + @param Buffer Pointer to the converted bytes array. + @param MaxBufferSize The maximum size of Buffer. + + @retval RETURN_SUCCESS Buffer is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If Length is not multiple of 2. + If PcdMaximumAsciiStringLength is not z= ero, + and Length is greater than + PcdMaximumAsciiStringLength. + If Length of characters from String con= tain + a character that is not valid hexadeci= mal + digit characters, or a Null-terminator. + @retval RETURN_BUFFER_TOO_SMALL If MaxBufferSize is less than (Length /= 2). +**/ +RETURN_STATUS +EFIAPI +AsciiStrHexToBytes ( + IN CONST CHAR8 *String, + IN UINTN Length, + OUT UINT8 *Buffer, + IN UINTN MaxBufferSize + ); + #ifndef DISABLE_NEW_DEPRECATED_INTERFACES =20 /** diff --git a/MdePkg/Library/BaseLib/SafeString.c b/MdePkg/Library/BaseLib/S= afeString.c index ede1c99..720f3f6 100644 --- a/MdePkg/Library/BaseLib/SafeString.c +++ b/MdePkg/Library/BaseLib/SafeString.c @@ -3060,3 +3060,594 @@ AsciiStrnToUnicodeStrS ( =20 return RETURN_SUCCESS; } + +/** + Convert a Null-terminated ASCII string to IPv6 address and prefix length. + + This function outputs a value of type IPv6_ADDRESS and may output a value + of type UINT8 by interpreting the contents of the ASCII string specified + by String. The format of the input ASCII string String is as follows: + + X:X:X:X:X:X:X:X[/P] + + X contains one to four hexadecimal digit characters in the range [0-9], = [a-f] and + [A-F]. X is converted to a value of type UINT16, whose low byte is store= d in low + memory address and high byte is stored in high memory address. P contain= s decimal + digit characters in the range [0-9]. The running zero in the beginning o= f P will + be ignored. /P is optional. + + When /P is not in the String, the function stops at the first character = that is + not a valid hexadecimal digit character after eight X's are converted. + + When /P is in the String, the function stops at the first character that= is not + a valid decimal digit character after P is converted. + + "::" can be used to compress one or more groups of X when X contains onl= y 0. + The "::" can only appear once in the String. + + If String is NULL, then ASSERT(). + + If Address is NULL, then ASSERT(). + + If EndPointer is not NULL and Address is translated from String, a point= er + to the character that stopped the scan is stored at the location pointed= to + by EndPointer. + + @param String Pointer to a Null-terminated ASCII stri= ng. + @param EndPointer Pointer to character that stops scan. + @param Address Pointer to the converted IPv6 address. + @param PrefixLength Pointer to the converted IPv6 address p= refix + length. MAX_UINT8 is returned when /P is + not in the String. + + @retval RETURN_SUCCESS Address is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If X contains more than four hexadecimal + digit characters. + If String contains "::" and number of X + is not less than 8. + If P starts with character that is not a + valid decimal digit character. + If the decimal number converted from P + exceeds 128. + +**/ +RETURN_STATUS +EFIAPI +AsciiStrToIpv6Address ( + IN CONST CHAR8 *String, + OUT CHAR8 **EndPointer, OPTIONAL + OUT IPv6_ADDRESS *Address, + OUT UINT8 *PrefixLength OPTIONAL + ) +{ + RETURN_STATUS Status; + UINTN AddressIndex; + UINTN Uintn; + IPv6_ADDRESS LocalAddress; + UINT8 LocalPrefixLength; + CONST CHAR8 *Pointer; + CHAR8 *End; + UINTN CompressStart; + BOOLEAN ExpectPrefix; + + LocalPrefixLength =3D MAX_UINT8; + CompressStart =3D ARRAY_SIZE (Address->Addr); + ExpectPrefix =3D FALSE; + + // + // None of String or Address shall be a null pointer. + // + SAFE_STRING_CONSTRAINT_CHECK ((String !=3D NULL), RETURN_INVALID_PARAMET= ER); + SAFE_STRING_CONSTRAINT_CHECK ((Address !=3D NULL), RETURN_INVALID_PARAME= TER); + + for (Pointer =3D String, AddressIndex =3D 0; AddressIndex < ARRAY_SIZE (= Address->Addr) + 1;) { + if (!InternalAsciiIsHexaDecimalDigitCharacter (*Pointer)) { + if (*Pointer !=3D ':') { + // + // ":" or "/" should be followed by digit characters. + // + return RETURN_INVALID_PARAMETER; + } + + // + // Meet second ":" after previous ":" or "/" + // or meet first ":" in the beginning of String. + // + if (ExpectPrefix) { + // + // ":" shall not be after "/" + // + return RETURN_INVALID_PARAMETER; + } + + if (CompressStart !=3D ARRAY_SIZE (Address->Addr) || AddressIndex = =3D=3D ARRAY_SIZE (Address->Addr)) { + // + // "::" can only appear once. + // "::" can only appear when address is not full length. + // + return RETURN_INVALID_PARAMETER; + } else { + // + // Remember the start of zero compressing. + // + CompressStart =3D AddressIndex; + Pointer++; + + if (CompressStart =3D=3D 0) { + if (*Pointer !=3D ':') { + // + // Single ":" shall not be in the beginning of String. + // + return RETURN_INVALID_PARAMETER; + } + Pointer++; + } + } + } + + if (!InternalAsciiIsHexaDecimalDigitCharacter (*Pointer)) { + if (*Pointer =3D=3D '/') { + // + // Might be optional "/P" after "::". + // + if (CompressStart !=3D AddressIndex) { + return RETURN_INVALID_PARAMETER; + } + } else { + break; + } + } else { + if (!ExpectPrefix) { + // + // Get X. + // + Status =3D AsciiStrHexToUintnS (Pointer, &End, &Uintn); + if (RETURN_ERROR (Status) || End - Pointer > 4) { + // + // Number of hexadecimal digit characters is no more than 4. + // + return RETURN_INVALID_PARAMETER; + } + Pointer =3D End; + // + // Uintn won't exceed MAX_UINT16 if number of hexadecimal digit ch= aracters is no more than 4. + // + LocalAddress.Addr[AddressIndex] =3D (UINT8) ((UINT16) Uintn >> 8); + LocalAddress.Addr[AddressIndex + 1] =3D (UINT8) Uintn; + AddressIndex +=3D 2; + } else { + // + // Get P, then exit the loop. + // + Status =3D AsciiStrDecimalToUintnS (Pointer, &End, &Uintn); + if (RETURN_ERROR (Status) || End =3D=3D Pointer || Uintn > 128) { + // + // Prefix length should not exceed 128. + // + return RETURN_INVALID_PARAMETER; + } + LocalPrefixLength =3D (UINT8) Uintn; + Pointer =3D End; + break; + } + } + + // + // Skip ':' or "/" + // + if (*Pointer =3D=3D '/') { + ExpectPrefix =3D TRUE; + } else if (*Pointer =3D=3D ':') { + if (AddressIndex =3D=3D ARRAY_SIZE (Address->Addr)) { + // + // Meet additional ":" after all 8 16-bit address + // + break; + } + } else { + // + // Meet other character that is not "/" or ":" after all 8 16-bit ad= dress + // + break; + } + Pointer++; + } + + if ((AddressIndex =3D=3D ARRAY_SIZE (Address->Addr) && CompressStart != =3D ARRAY_SIZE (Address->Addr)) || + (AddressIndex !=3D ARRAY_SIZE (Address->Addr) && CompressStart =3D=3D = ARRAY_SIZE (Address->Addr)) + ) { + // + // Full length of address shall not have compressing zeros. + // Non-full length of address shall have compressing zeros. + // + return RETURN_INVALID_PARAMETER; + } + CopyMem (&Address->Addr[0], &LocalAddress.Addr[0], CompressStart); + ZeroMem (&Address->Addr[CompressStart], ARRAY_SIZE (Address->Addr) - Add= ressIndex); + CopyMem ( + &Address->Addr[CompressStart + ARRAY_SIZE (Address->Addr) - AddressInd= ex], + &LocalAddress.Addr[CompressStart], + AddressIndex - CompressStart + ); + + if (PrefixLength !=3D NULL) { + *PrefixLength =3D LocalPrefixLength; + } + if (EndPointer !=3D NULL) { + *EndPointer =3D (CHAR8 *) Pointer; + } + + return RETURN_SUCCESS; +} + +/** + Convert a Null-terminated ASCII string to IPv4 address and prefix length. + + This function outputs a value of type IPv4_ADDRESS and may output a value + of type UINT8 by interpreting the contents of the ASCII string specified + by String. The format of the input ASCII string String is as follows: + + D.D.D.D[/P] + + D and P are decimal digit characters in the range [0-9]. The running zer= o in + the beginning of D and P will be ignored. /P is optional. + + When /P is not in the String, the function stops at the first character = that is + not a valid decimal digit character after four D's are converted. + + When /P is in the String, the function stops at the first character that= is not + a valid decimal digit character after P is converted. + + If String is NULL, then ASSERT(). + + If Address is NULL, then ASSERT(). + + If EndPointer is not NULL and Address is translated from String, a point= er + to the character that stopped the scan is stored at the location pointed= to + by EndPointer. + + @param String Pointer to a Null-terminated ASCII stri= ng. + @param EndPointer Pointer to character that stops scan. + @param Address Pointer to the converted IPv4 address. + @param PrefixLength Pointer to the converted IPv4 address p= refix + length. MAX_UINT8 is returned when /P is + not in the String. + + @retval RETURN_SUCCESS Address is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If String is not in the correct format. + If any decimal number converted from D + exceeds 255. + If the decimal number converted from P + exceeds 32. + +**/ +RETURN_STATUS +EFIAPI +AsciiStrToIpv4Address ( + IN CONST CHAR8 *String, + OUT CHAR8 **EndPointer, OPTIONAL + OUT IPv4_ADDRESS *Address, + OUT UINT8 *PrefixLength OPTIONAL + ) +{ + RETURN_STATUS Status; + UINTN AddressIndex; + UINTN Uintn; + IPv4_ADDRESS LocalAddress; + UINT8 LocalPrefixLength; + CHAR8 *Pointer; + + LocalPrefixLength =3D MAX_UINT8; + + // + // None of String or Address shall be a null pointer. + // + SAFE_STRING_CONSTRAINT_CHECK ((String !=3D NULL), RETURN_INVALID_PARAMET= ER); + SAFE_STRING_CONSTRAINT_CHECK ((Address !=3D NULL), RETURN_INVALID_PARAME= TER); + + for (Pointer =3D (CHAR8 *) String, AddressIndex =3D 0; AddressIndex < AR= RAY_SIZE (Address->Addr) + 1;) { + if (!InternalAsciiIsDecimalDigitCharacter (*Pointer)) { + // + // D or P contains invalid characters. + // + break; + } + + // + // Get D or P. + // + Status =3D AsciiStrDecimalToUintnS ((CONST CHAR8 *) Pointer, &Pointer,= &Uintn); + if (RETURN_ERROR (Status)) { + return RETURN_INVALID_PARAMETER; + } + if (AddressIndex =3D=3D ARRAY_SIZE (Address->Addr)) { + // + // It's P. + // + if (Uintn > 32) { + return RETURN_INVALID_PARAMETER; + } + LocalPrefixLength =3D (UINT8) Uintn; + } else { + // + // It's D. + // + if (Uintn > MAX_UINT8) { + return RETURN_INVALID_PARAMETER; + } + LocalAddress.Addr[AddressIndex] =3D (UINT8) Uintn; + AddressIndex++; + } + + // + // Check the '.' or '/', depending on the AddressIndex. + // + if (AddressIndex =3D=3D ARRAY_SIZE (Address->Addr)) { + if (*Pointer =3D=3D '/') { + // + // '/P' is in the String. + // Skip "/" and get P in next loop. + // + Pointer++; + } else { + // + // '/P' is not in the String. + // + break; + } + } else if (AddressIndex < ARRAY_SIZE (Address->Addr)) { + if (*Pointer =3D=3D '.') { + // + // D should be followed by '.' + // + Pointer++; + } else { + return RETURN_INVALID_PARAMETER; + } + } + } + + if (AddressIndex < ARRAY_SIZE (Address->Addr)) { + return RETURN_INVALID_PARAMETER; + } + + CopyMem (Address, &LocalAddress, sizeof (*Address)); + if (PrefixLength !=3D NULL) { + *PrefixLength =3D LocalPrefixLength; + } + if (EndPointer !=3D NULL) { + *EndPointer =3D Pointer; + } + + return RETURN_SUCCESS; +} + +/** + Convert a Null-terminated ASCII GUID string to a value of type + EFI_GUID. + + This function outputs a GUID value by interpreting the contents of + the ASCII string specified by String. The format of the input + ASCII string String consists of 36 characters, as follows: + + aabbccdd-eeff-gghh-iijj-kkllmmnnoopp + + The pairs aa - pp are two characters in the range [0-9], [a-f] and + [A-F], with each pair representing a single byte hexadecimal value. + + The mapping between String and the EFI_GUID structure is as follows: + aa Data1[24:31] + bb Data1[16:23] + cc Data1[8:15] + dd Data1[0:7] + ee Data2[8:15] + ff Data2[0:7] + gg Data3[8:15] + hh Data3[0:7] + ii Data4[0:7] + jj Data4[8:15] + kk Data4[16:23] + ll Data4[24:31] + mm Data4[32:39] + nn Data4[40:47] + oo Data4[48:55] + pp Data4[56:63] + + If String is NULL, then ASSERT(). + If Guid is NULL, then ASSERT(). + + @param String Pointer to a Null-terminated ASCII stri= ng. + @param Guid Pointer to the converted GUID. + + @retval RETURN_SUCCESS Guid is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If String is not as the above format. + +**/ +RETURN_STATUS +EFIAPI +AsciiStrToGuid ( + IN CONST CHAR8 *String, + OUT GUID *Guid + ) +{ + RETURN_STATUS Status; + GUID LocalGuid; + + // + // None of String or Guid shall be a null pointer. + // + SAFE_STRING_CONSTRAINT_CHECK ((String !=3D NULL), RETURN_INVALID_PARAMET= ER); + SAFE_STRING_CONSTRAINT_CHECK ((Guid !=3D NULL), RETURN_INVALID_PARAMETER= ); + + // + // Get aabbccdd in big-endian. + // + Status =3D AsciiStrHexToBytes (String, 2 * sizeof (LocalGuid.Data1), (UI= NT8 *) &LocalGuid.Data1, sizeof (LocalGuid.Data1)); + if (RETURN_ERROR (Status) || String[2 * sizeof (LocalGuid.Data1)] !=3D '= -') { + return RETURN_INVALID_PARAMETER; + } + // + // Convert big-endian to little-endian. + // + LocalGuid.Data1 =3D SwapBytes32 (LocalGuid.Data1); + String +=3D 2 * sizeof (LocalGuid.Data1) + 1; + + // + // Get eeff in big-endian. + // + Status =3D AsciiStrHexToBytes (String, 2 * sizeof (LocalGuid.Data2), (UI= NT8 *) &LocalGuid.Data2, sizeof (LocalGuid.Data2)); + if (RETURN_ERROR (Status) || String[2 * sizeof (LocalGuid.Data2)] !=3D '= -') { + return RETURN_INVALID_PARAMETER; + } + // + // Convert big-endian to little-endian. + // + LocalGuid.Data2 =3D SwapBytes16 (LocalGuid.Data2); + String +=3D 2 * sizeof (LocalGuid.Data2) + 1; + + // + // Get gghh in big-endian. + // + Status =3D AsciiStrHexToBytes (String, 2 * sizeof (LocalGuid.Data3), (UI= NT8 *) &LocalGuid.Data3, sizeof (LocalGuid.Data3)); + if (RETURN_ERROR (Status) || String[2 * sizeof (LocalGuid.Data3)] !=3D '= -') { + return RETURN_INVALID_PARAMETER; + } + // + // Convert big-endian to little-endian. + // + LocalGuid.Data3 =3D SwapBytes16 (LocalGuid.Data3); + String +=3D 2 * sizeof (LocalGuid.Data3) + 1; + + // + // Get iijj. + // + Status =3D AsciiStrHexToBytes (String, 2 * 2, &LocalGuid.Data4[0], 2); + if (RETURN_ERROR (Status) || String[2 * 2] !=3D '-') { + return RETURN_INVALID_PARAMETER; + } + String +=3D 2 * 2 + 1; + + // + // Get kkllmmnnoopp. + // + Status =3D AsciiStrHexToBytes (String, 2 * 6, &LocalGuid.Data4[2], 6); + if (RETURN_ERROR (Status)) { + return RETURN_INVALID_PARAMETER; + } + + CopyGuid (Guid, &LocalGuid); + return RETURN_SUCCESS; +} + +/** + Convert a Null-terminated ASCII hexadecimal string to a byte array. + + This function outputs a byte array by interpreting the contents of + the ASCII string specified by String in hexadecimal format. The format of + the input ASCII string String is: + + [XX]* + + X is a hexadecimal digit character in the range [0-9], [a-f] and [A-F]. + The function decodes every two hexadecimal digit characters as one byte.= The + decoding stops after Length of characters and outputs Buffer containing + (Length / 2) bytes. + + If String is NULL, then ASSERT(). + + If Buffer is NULL, then ASSERT(). + + If Length is not multiple of 2, then ASSERT(). + + If PcdMaximumAsciiStringLength is not zero and Length is greater than + PcdMaximumAsciiStringLength, then ASSERT(). + + If MaxBufferSize is less than (Length / 2), then ASSERT(). + + @param String Pointer to a Null-terminated ASCII stri= ng. + @param Length The number of ASCII characters to decod= e. + @param Buffer Pointer to the converted bytes array. + @param MaxBufferSize The maximum size of Buffer. + + @retval RETURN_SUCCESS Buffer is translated from String. + @retval RETURN_INVALID_PARAMETER If String is NULL. + If Data is NULL. + If Length is not multiple of 2. + If PcdMaximumAsciiStringLength is not z= ero, + and Length is greater than + PcdMaximumAsciiStringLength. + If Length of characters from String con= tain + a character that is not valid hexadeci= mal + digit characters, or a Null-terminator. + @retval RETURN_BUFFER_TOO_SMALL If MaxBufferSize is less than (Length /= 2). +**/ +RETURN_STATUS +EFIAPI +AsciiStrHexToBytes ( + IN CONST CHAR8 *String, + IN UINTN Length, + OUT UINT8 *Buffer, + IN UINTN MaxBufferSize + ) +{ + UINTN Index; + + // + // 1. None of String or Buffer shall be a null pointer. + // + SAFE_STRING_CONSTRAINT_CHECK ((String !=3D NULL), RETURN_INVALID_PARAMET= ER); + SAFE_STRING_CONSTRAINT_CHECK ((Buffer !=3D NULL), RETURN_INVALID_PARAMET= ER); + + // + // 2. Length shall not be greater than ASCII_RSIZE_MAX. + // + if (ASCII_RSIZE_MAX !=3D 0) { + SAFE_STRING_CONSTRAINT_CHECK ((Length <=3D ASCII_RSIZE_MAX), RETURN_IN= VALID_PARAMETER); + } + + // + // 3. Length shall not be odd. + // + SAFE_STRING_CONSTRAINT_CHECK (((Length & BIT0) =3D=3D 0), RETURN_INVALID= _PARAMETER); + + // + // 4. MaxBufferSize shall equal to or greater than Length / 2. + // + SAFE_STRING_CONSTRAINT_CHECK ((MaxBufferSize >=3D Length / 2), RETURN_BU= FFER_TOO_SMALL); + + // + // 5. String shall not contains invalid hexadecimal digits. + // + for (Index =3D 0; Index < Length; Index++) { + if (!InternalAsciiIsHexaDecimalDigitCharacter (String[Index])) { + break; + } + } + if (Index !=3D Length) { + return RETURN_INVALID_PARAMETER; + } + + // + // Convert the hex string to bytes. + // + for(Index =3D 0; Index < Length; Index++) { + + // + // For even characters, write the upper nibble for each buffer byte, + // and for even characters, the lower nibble. + // + if ((Index & BIT0) =3D=3D 0) { + Buffer[Index / 2] =3D (UINT8) InternalAsciiHexCharToUintn (String[I= ndex]) << 4; + } else { + Buffer[Index / 2] |=3D (UINT8) InternalAsciiHexCharToUintn (String[I= ndex]); + } + } + return RETURN_SUCCESS; +} + --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 14:36:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487739070913761.5580040296383; Tue, 21 Feb 2017 20:51:10 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 18AB88225A; Tue, 21 Feb 2017 20:50:59 -0800 (PST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 4BC738221C for ; Tue, 21 Feb 2017 20:50:57 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2017 20:50:57 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga001.jf.intel.com with ESMTP; 21 Feb 2017 20:50:56 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,192,1484035200"; d="scan'208";a="1100867159" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 22 Feb 2017 12:50:42 +0800 Message-Id: <20170222045047.558308-7-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20170222045047.558308-1-ruiyu.ni@intel.com> References: <20170222045047.558308-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 06/11] MdePkg/UefiDevicePathLib: Use BaseLib string conversion services 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: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Update UefiDevicePathLib to use StrToGuid/StrHexToBytes /StrToIpv4Address/StrToIpv6Address provided by BaseLib. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Liming Gao --- .../Library/UefiDevicePathLib/DevicePathFromText.c | 221 ++---------------= ---- 1 file changed, 17 insertions(+), 204 deletions(-) diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c b/MdePkg= /Library/UefiDevicePathLib/DevicePathFromText.c index e2b06a2..ae38859 100644 --- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c @@ -326,187 +326,6 @@ Strtoi64 ( } =20 /** - Converts a list of string to a specified buffer. - - @param Buf The output buffer that contains the string. - @param BufferLength The length of the buffer - @param Str The input string that contains the hex number - - @retval EFI_SUCCESS The string was successfully converted to the buff= er. - -**/ -EFI_STATUS -StrToBuf ( - OUT UINT8 *Buf, - IN UINTN BufferLength, - IN CHAR16 *Str - ) -{ - UINTN Index; - UINTN StrLength; - UINT8 Digit; - UINT8 Byte; - - Digit =3D 0; - - // - // Two hex char make up one byte - // - StrLength =3D BufferLength * sizeof (CHAR16); - - for(Index =3D 0; Index < StrLength; Index++, Str++) { - - if ((*Str >=3D L'a') && (*Str <=3D L'f')) { - Digit =3D (UINT8) (*Str - L'a' + 0x0A); - } else if ((*Str >=3D L'A') && (*Str <=3D L'F')) { - Digit =3D (UINT8) (*Str - L'A' + 0x0A); - } else if ((*Str >=3D L'0') && (*Str <=3D L'9')) { - Digit =3D (UINT8) (*Str - L'0'); - } else { - return EFI_INVALID_PARAMETER; - } - - // - // For odd characters, write the upper nibble for each buffer byte, - // and for even characters, the lower nibble. - // - if ((Index & 1) =3D=3D 0) { - Byte =3D (UINT8) (Digit << 4); - } else { - Byte =3D Buf[Index / 2]; - Byte &=3D 0xF0; - Byte =3D (UINT8) (Byte | Digit); - } - - Buf[Index / 2] =3D Byte; - } - - return EFI_SUCCESS; -} - -/** - Converts a string to GUID value. - Guid Format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - - @param Str The registry format GUID string that contains th= e GUID value. - @param Guid A pointer to the converted GUID value. - - @retval EFI_SUCCESS The GUID string was successfully converted to th= e GUID value. - @retval EFI_UNSUPPORTED The input string is not in registry format. - @return others Some error occurred when converting part of GUID= value. - -**/ -EFI_STATUS -DevicePathLibStrToGuid ( - IN CHAR16 *Str, - OUT EFI_GUID *Guid - ) -{ - // - // Get the first UINT32 data - // - Guid->Data1 =3D (UINT32) StrHexToUint64 (Str); - while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) { - Str ++; - } - =20 - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - =20 - // - // Get the second UINT16 data - // - Guid->Data2 =3D (UINT16) StrHexToUint64 (Str); - while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) { - Str ++; - } - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - =20 - // - // Get the third UINT16 data - // - Guid->Data3 =3D (UINT16) StrHexToUint64 (Str); - while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) { - Str ++; - } - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - - // - // Get the following 8 bytes data - // =20 - StrToBuf (&Guid->Data4[0], 2, Str); - // - // Skip 2 byte hex chars - // - Str +=3D 2 * 2; - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - StrToBuf (&Guid->Data4[2], 6, Str); - - return EFI_SUCCESS; -} - -/** - Converts a string to IPv4 address - - @param Str A string representation of IPv4 address. - @param IPv4Addr A pointer to the converted IPv4 address. - -**/ -VOID -StrToIPv4Addr ( - IN OUT CHAR16 **Str, - OUT EFI_IPv4_ADDRESS *IPv4Addr - ) -{ - UINTN Index; - - for (Index =3D 0; Index < 4; Index++) { - IPv4Addr->Addr[Index] =3D (UINT8) Strtoi (SplitStr (Str, L'.')); - } -} - -/** - Converts a string to IPv4 address - - @param Str A string representation of IPv6 address. - @param IPv6Addr A pointer to the converted IPv6 address. - -**/ -VOID -StrToIPv6Addr ( - IN OUT CHAR16 **Str, - OUT EFI_IPv6_ADDRESS *IPv6Addr - ) -{ - UINTN Index; - UINT16 Data; - - for (Index =3D 0; Index < 8; Index++) { - Data =3D (UINT16) StrHexToUintn (SplitStr (Str, L':')); - IPv6Addr->Addr[Index * 2] =3D (UINT8) (Data >> 8); - IPv6Addr->Addr[Index * 2 + 1] =3D (UINT8) (Data & 0xff); - } -} - -/** Converts a Unicode string to ASCII string. =20 @param Str The equivalent Unicode string @@ -567,9 +386,7 @@ DevPathFromTextGenericPath ( (UINT16) (sizeof (EFI_DEVICE_PATH_PROTOCOL) + DataLength) ); =20 - if (DataLength !=3D 0) { - StrToBuf ((UINT8 *) (Node + 1), DataLength, DataStr); - } + StrHexToBytes (DataStr, DataLength * 2, (UINT8 *) (Node + 1), DataLength= ); return Node; } =20 @@ -740,8 +557,8 @@ ConvertFromTextVendor ( (UINT16) (sizeof (VENDOR_DEVICE_PATH)= + Length) ); =20 - DevicePathLibStrToGuid (GuidStr, &Vendor->Guid); - StrToBuf (((UINT8 *) Vendor) + sizeof (VENDOR_DEVICE_PATH), Length, Data= Str); + StrToGuid (GuidStr, &Vendor->Guid); + StrHexToBytes (DataStr, Length * 2, (UINT8 *) (Vendor + 1), Length); =20 return (EFI_DEVICE_PATH_PROTOCOL *) Vendor; } @@ -1438,7 +1255,6 @@ DevPathFromTextInfiniband ( CHAR16 *SidStr; CHAR16 *TidStr; CHAR16 *DidStr; - EFI_GUID PortGid; INFINIBAND_DEVICE_PATH *InfiniBand; =20 FlagsStr =3D GetNextParamStr (&TextDeviceNode); @@ -1453,8 +1269,7 @@ DevPathFromTextInfiniband ( ); =20 InfiniBand->ResourceFlags =3D (UINT32) Strtoi (FlagsStr); - DevicePathLibStrToGuid (GuidStr, &PortGid); - CopyMem (InfiniBand->PortGid, &PortGid, sizeof (EFI_GUID)); + StrToGuid (GuidStr, (EFI_GUID *) InfiniBand->PortGid); Strtoi64 (SidStr, &InfiniBand->ServiceId); Strtoi64 (TidStr, &InfiniBand->TargetPortId); Strtoi64 (DidStr, &InfiniBand->DeviceId); @@ -1985,7 +1800,7 @@ DevPathFromTextMAC ( MACDevPath->IfType =3D (UINT8) Strtoi (IfTypeStr); =20 Length =3D sizeof (EFI_MAC_ADDRESS); - StrToBuf (&MACDevPath->MacAddress.Addr[0], Length, AddressStr); + StrHexToBytes (AddressStr, Length * 2, MACDevPath->MacAddress.Addr, Leng= th); =20 return (EFI_DEVICE_PATH_PROTOCOL *) MACDevPath; } @@ -2049,7 +1864,7 @@ DevPathFromTextIPv4 ( (UINT16) sizeof (IPv4_DEV= ICE_PATH) ); =20 - StrToIPv4Addr (&RemoteIPStr, &IPv4->RemoteIpAddress); + StrToIpv4Address (RemoteIPStr, NULL, &IPv4->RemoteIpAddress, NULL); IPv4->Protocol =3D (UINT16) NetworkProtocolFromText (ProtocolStr); if (StrCmp (TypeStr, L"Static") =3D=3D 0) { IPv4->StaticIpAddress =3D TRUE; @@ -2057,10 +1872,10 @@ DevPathFromTextIPv4 ( IPv4->StaticIpAddress =3D FALSE; } =20 - StrToIPv4Addr (&LocalIPStr, &IPv4->LocalIpAddress); + StrToIpv4Address (LocalIPStr, NULL, &IPv4->LocalIpAddress, NULL); if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*SubnetMaskStr)) { - StrToIPv4Addr (&GatewayIPStr, &IPv4->GatewayIpAddress); - StrToIPv4Addr (&SubnetMaskStr, &IPv4->SubnetMask); + StrToIpv4Address (GatewayIPStr, NULL, &IPv4->GatewayIpAddress, NULL); + StrToIpv4Address (SubnetMaskStr, NULL, &IPv4->SubnetMask, NULL); } else { ZeroMem (&IPv4->GatewayIpAddress, sizeof (IPv4->GatewayIpAddress)); ZeroMem (&IPv4->SubnetMask, sizeof (IPv4->SubnetMask)); @@ -2105,7 +1920,7 @@ DevPathFromTextIPv6 ( (UINT16) sizeof (IPv6_DEV= ICE_PATH) ); =20 - StrToIPv6Addr (&RemoteIPStr, &IPv6->RemoteIpAddress); + StrToIpv6Address (RemoteIPStr, NULL, &IPv6->RemoteIpAddress, NULL); IPv6->Protocol =3D (UINT16) NetworkProtocolFromText (ProtocolStr); if (StrCmp (TypeStr, L"Static") =3D=3D 0) { IPv6->IpAddressOrigin =3D 0; @@ -2115,9 +1930,9 @@ DevPathFromTextIPv6 ( IPv6->IpAddressOrigin =3D 2; } =20 - StrToIPv6Addr (&LocalIPStr, &IPv6->LocalIpAddress); + StrToIpv6Address (LocalIPStr, NULL, &IPv6->LocalIpAddress, NULL); if (!IS_NULL (*GatewayIPStr) && !IS_NULL (*PrefixLengthStr)) { - StrToIPv6Addr (&GatewayIPStr, &IPv6->GatewayIpAddress); + StrToIpv6Address (GatewayIPStr, NULL, &IPv6->GatewayIpAddress, NULL); IPv6->PrefixLength =3D (UINT8) Strtoi (PrefixLengthStr); } else { ZeroMem (&IPv6->GatewayIpAddress, sizeof (IPv6->GatewayIpAddress)); @@ -2947,7 +2762,6 @@ DevPathFromTextHD ( CHAR16 *StartStr; CHAR16 *SizeStr; UINT32 Signature32; - EFI_GUID SignatureGuid; HARDDRIVE_DEVICE_PATH *Hd; =20 PartitionStr =3D GetNextParamStr (&TextDeviceNode); @@ -2976,8 +2790,7 @@ DevPathFromTextHD ( Hd->SignatureType =3D SIGNATURE_TYPE_GUID; Hd->MBRType =3D 0x02; =20 - DevicePathLibStrToGuid (SignatureStr, &SignatureGuid); - CopyMem (Hd->Signature, &SignatureGuid, sizeof (EFI_GUID)); + StrToGuid (SignatureStr, (EFI_GUID *) Hd->Signature); } else { Hd->SignatureType =3D (UINT8) Strtoi (TypeStr); } @@ -3091,7 +2904,7 @@ DevPathFromTextMedia ( (UINT16) sizeof (MEDIA_PROTOC= OL_DEVICE_PATH) ); =20 - DevicePathLibStrToGuid (GuidStr, &Media->Protocol); + StrToGuid (GuidStr, &Media->Protocol); =20 return (EFI_DEVICE_PATH_PROTOCOL *) Media; } @@ -3119,7 +2932,7 @@ DevPathFromTextFv ( (UINT16) sizeof (MEDIA_FW_VOL_D= EVICE_PATH) ); =20 - DevicePathLibStrToGuid (GuidStr, &Fv->FvName); + StrToGuid (GuidStr, &Fv->FvName); =20 return (EFI_DEVICE_PATH_PROTOCOL *) Fv; } @@ -3147,7 +2960,7 @@ DevPathFromTextFvFile ( (UINT16) sizeof (MEDIA= _FW_VOL_FILEPATH_DEVICE_PATH) ); =20 - DevicePathLibStrToGuid (GuidStr, &FvFile->FvFileName); + StrToGuid (GuidStr, &FvFile->FvFileName); =20 return (EFI_DEVICE_PATH_PROTOCOL *) FvFile; } @@ -3219,7 +3032,7 @@ DevPathFromTextRamDisk ( Strtoi64 (EndingAddrStr, &EndingAddr); WriteUnaligned64 ((UINT64 *) &(RamDisk->EndingAddr[0]), EndingAddr); RamDisk->Instance =3D (UINT16) Strtoi (InstanceStr); - DevicePathLibStrToGuid (TypeGuidStr, &RamDisk->TypeGuid); + StrToGuid (TypeGuidStr, &RamDisk->TypeGuid); =20 return (EFI_DEVICE_PATH_PROTOCOL *) RamDisk; } --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 14:36:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487739074188303.6482634070983; Tue, 21 Feb 2017 20:51:14 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5BBE682259; Tue, 21 Feb 2017 20:51:01 -0800 (PST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 4940782257 for ; Tue, 21 Feb 2017 20:50:58 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2017 20:50:58 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga001.jf.intel.com with ESMTP; 21 Feb 2017 20:50:57 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,192,1484035200"; d="scan'208";a="1100867165" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 22 Feb 2017 12:50:43 +0800 Message-Id: <20170222045047.558308-8-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20170222045047.558308-1-ruiyu.ni@intel.com> References: <20170222045047.558308-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 07/11] MdeModulePkg/CapsuleApp: Use StrToGuid in BaseLib 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: , Cc: Jiewen Yao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Jiewen Yao --- MdeModulePkg/Application/CapsuleApp/AppSupport.c | 140 +------------------= ---- MdeModulePkg/Application/CapsuleApp/CapsuleApp.c | 25 +--- 2 files changed, 4 insertions(+), 161 deletions(-) diff --git a/MdeModulePkg/Application/CapsuleApp/AppSupport.c b/MdeModulePk= g/Application/CapsuleApp/AppSupport.c index edc5f29..e39ab20 100644 --- a/MdeModulePkg/Application/CapsuleApp/AppSupport.c +++ b/MdeModulePkg/Application/CapsuleApp/AppSupport.c @@ -1,7 +1,7 @@ /** @file A shell application that triggers capsule update process. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -64,144 +64,6 @@ GetArg ( } =20 /** - Converts a list of string to a specified buffer. - - @param[out] Buf The output buffer that contains the string. - @param[in] BufferLength The length of the buffer - @param[in] Str The input string that contains the hex number - - @retval EFI_SUCCESS The string was successfully converted to the buff= er. - -**/ -EFI_STATUS -InternalStrToBuf ( - OUT UINT8 *Buf, - IN UINTN BufferLength, - IN CHAR16 *Str - ) -{ - UINTN Index; - UINTN StrLength; - UINT8 Digit; - UINT8 Byte; - - Digit =3D 0; - - // - // Two hex char make up one byte - // - StrLength =3D BufferLength * sizeof (CHAR16); - - for(Index =3D 0; Index < StrLength; Index++, Str++) { - - if ((*Str >=3D L'a') && (*Str <=3D L'f')) { - Digit =3D (UINT8) (*Str - L'a' + 0x0A); - } else if ((*Str >=3D L'A') && (*Str <=3D L'F')) { - Digit =3D (UINT8) (*Str - L'A' + 0x0A); - } else if ((*Str >=3D L'0') && (*Str <=3D L'9')) { - Digit =3D (UINT8) (*Str - L'0'); - } else { - return EFI_INVALID_PARAMETER; - } - - // - // For odd characters, write the upper nibble for each buffer byte, - // and for even characters, the lower nibble. - // - if ((Index & 1) =3D=3D 0) { - Byte =3D (UINT8) (Digit << 4); - } else { - Byte =3D Buf[Index / 2]; - Byte &=3D 0xF0; - Byte =3D (UINT8) (Byte | Digit); - } - - Buf[Index / 2] =3D Byte; - } - - return EFI_SUCCESS; -} - -/** - Converts a string to GUID value. - Guid Format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - - @param[in] Str The registry format GUID string that contai= ns the GUID value. - @param[out] Guid A pointer to the converted GUID value. - - @retval EFI_SUCCESS The GUID string was successfully converted to th= e GUID value. - @retval EFI_UNSUPPORTED The input string is not in registry format. - @return others Some error occurred when converting part of GUID= value. - -**/ -EFI_STATUS -InternalStrToGuid ( - IN CHAR16 *Str, - OUT EFI_GUID *Guid - ) -{ - // - // Get the first UINT32 data - // - Guid->Data1 =3D (UINT32) StrHexToUint64 (Str); - while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) { - Str ++; - } - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - - // - // Get the second UINT16 data - // - Guid->Data2 =3D (UINT16) StrHexToUint64 (Str); - while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) { - Str ++; - } - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - - // - // Get the third UINT16 data - // - Guid->Data3 =3D (UINT16) StrHexToUint64 (Str); - while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) { - Str ++; - } - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - - // - // Get the following 8 bytes data - // - InternalStrToBuf (&Guid->Data4[0], 2, Str); - // - // Skip 2 byte hex chars - // - Str +=3D 2 * 2; - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - InternalStrToBuf (&Guid->Data4[2], 6, Str); - - return EFI_SUCCESS; -} - -/** Return File System Volume containing this shell application. =20 @return File System Volume containing this shell application. diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c b/MdeModulePk= g/Application/CapsuleApp/CapsuleApp.c index 5b8c147..eea40b7 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleApp.c @@ -1,7 +1,7 @@ /** @file A shell application that triggers capsule update process. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -143,24 +143,6 @@ WriteFileFromBuffer ( ); =20 /** - Converts a string to GUID value. - Guid Format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - - @param[in] Str The registry format GUID string that contai= ns the GUID value. - @param[out] Guid A pointer to the converted GUID value. - - @retval EFI_SUCCESS The GUID string was successfully converted to th= e GUID value. - @retval EFI_UNSUPPORTED The input string is not in registry format. - @return others Some error occurred when converting part of GUID= value. - -**/ -EFI_STATUS -InternalStrToGuid ( - IN CHAR16 *Str, - OUT EFI_GUID *Guid - ); - -/** =20 This function parse application ARG. =20 @@ -782,10 +764,9 @@ UefiMain ( // // FMP->GetImage() // - Status =3D InternalStrToGuid(Argv[3], &ImageTypeId); - if (EFI_ERROR(Status)) { + if (RETURN_ERROR (StrToGuid (Argv[3], &ImageTypeId)) || (Argv[3][G= UID_STRING_LENGTH] !=3D L'\0')) { Print (L"Invalid ImageTypeId - %s\n", Argv[3]); - return Status; + return EFI_INVALID_PARAMETER; } ImageIndex =3D StrDecimalToUintn(Argv[4]); if (StrCmp(Argv[5], L"-O") =3D=3D 0) { --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 14:36:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487739080718509.6430149465085; Tue, 21 Feb 2017 20:51:20 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D065582268; Tue, 21 Feb 2017 20:51:01 -0800 (PST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 1CAE28225B for ; Tue, 21 Feb 2017 20:50:59 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2017 20:50:58 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga001.jf.intel.com with ESMTP; 21 Feb 2017 20:50:58 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,192,1484035200"; d="scan'208";a="1100867169" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 22 Feb 2017 12:50:44 +0800 Message-Id: <20170222045047.558308-9-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20170222045047.558308-1-ruiyu.ni@intel.com> References: <20170222045047.558308-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 08/11] SecurityPkg/SecureBootConfigDxe: Use StrToGuid in BaseLib 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: , Cc: Jiewen Yao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Jiewen Yao --- .../SecureBootConfigDxe/SecureBootConfigImpl.c | 11 +- .../SecureBootConfigDxe/SecureBootConfigImpl.h | 22 +--- .../SecureBootConfigDxe/SecureBootConfigMisc.c | 141 +----------------= ---- 3 files changed, 6 insertions(+), 168 deletions(-) diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBo= otConfigImpl.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/Secu= reBootConfigImpl.c index 0d96185..9b7d0c1 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gImpl.c +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gImpl.c @@ -1,7 +1,7 @@ /** @file HII Config Access protocol implementation of SecureBoot configuration mo= dule. =20 -Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2017, 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 @@ -3636,12 +3636,9 @@ SecureBootCallback ( case KEY_SECURE_BOOT_SIGNATURE_GUID_DBX: case KEY_SECURE_BOOT_SIGNATURE_GUID_DBT: ASSERT (Private->SignatureGUID !=3D NULL); - Status =3D StringToGuid ( - IfrNvData->SignatureGuid, - StrLen (IfrNvData->SignatureGuid), - Private->SignatureGUID - ); - if (EFI_ERROR (Status)) { + if (RETURN_ERROR (StrToGuid (IfrNvData->SignatureGuid, Private->Sign= atureGUID)) || + (IfrNvData->SignatureGuid[GUID_STRING_LENGTH] !=3D L'\0')) { + Status =3D EFI_INVALID_PARAMETER; break; } =20 diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBo= otConfigImpl.h b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/Secu= reBootConfigImpl.h index 5055a9e..aa58c44 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gImpl.h +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gImpl.h @@ -2,7 +2,7 @@ The header file of HII Config Access protocol implementation of SecureBo= ot configuration module. =20 -Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2017, 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 @@ -479,26 +479,6 @@ Int2OctStr ( IN UINTN OSSizeInBytes ); =20 - -/** - Convert a String to Guid Value. - - @param[in] Str Specifies the String to be converted. - @param[in] StrLen Number of Unicode Characters of String (exclusiv= e \0) - @param[out] Guid Return the result Guid value. - - @retval EFI_SUCCESS The operation is finished successfully. - @retval EFI_NOT_FOUND Invalid string. - -**/ -EFI_STATUS -StringToGuid ( - IN CHAR16 *Str, - IN UINTN StrLen, - OUT EFI_GUID *Guid - ); - - /** Worker function that prints an EFI_GUID into specified Buffer. =20 diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBo= otConfigMisc.c b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/Secu= reBootConfigMisc.c index a83504e..038707c 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gMisc.c +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gMisc.c @@ -1,7 +1,7 @@ /** @file Helper functions for SecureBoot configuration module. =20 -Copyright (c) 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2017, 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 @@ -152,145 +152,6 @@ Int2OctStr ( return EFI_SUCCESS; } =20 - - -/** - Convert a String to Guid Value. - - @param[in] Str Specifies the String to be converted. - @param[in] StrLen Number of Unicode Characters of String (exclusiv= e \0) - @param[out] Guid Return the result Guid value. - - @retval EFI_SUCCESS The operation is finished successfully. - @retval EFI_NOT_FOUND Invalid string. - -**/ -EFI_STATUS -StringToGuid ( - IN CHAR16 *Str,=20 - IN UINTN StrLen,=20 - OUT EFI_GUID *Guid - ) -{ - CHAR16 *PtrBuffer; - CHAR16 *PtrPosition; - UINT16 *Buffer; - UINTN Data; - UINTN Index; - UINT16 Digits[3]; - - Buffer =3D (CHAR16 *) AllocateZeroPool (sizeof (CHAR16) * (StrLen + 1)); - if (Buffer =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - StrCpyS (Buffer, (StrLen + 1), Str); - - // - // Data1 - // - PtrBuffer =3D Buffer; - PtrPosition =3D PtrBuffer;=20 - while (*PtrBuffer !=3D L'\0') { - if (*PtrBuffer =3D=3D L'-') { - break; - } - PtrBuffer++; - } - if (*PtrBuffer =3D=3D L'\0') { - FreePool (Buffer); - return EFI_NOT_FOUND; - } - - *PtrBuffer =3D L'\0'; - Data =3D StrHexToUintn (PtrPosition); - Guid->Data1 =3D (UINT32)Data; - - // - // Data2 - // - PtrBuffer++; - PtrPosition =3D PtrBuffer; - while (*PtrBuffer !=3D L'\0') { - if (*PtrBuffer =3D=3D L'-') { - break; - } - PtrBuffer++; - } - if (*PtrBuffer =3D=3D L'\0') { - FreePool (Buffer); - return EFI_NOT_FOUND; - } - *PtrBuffer =3D L'\0'; - Data =3D StrHexToUintn (PtrPosition); - Guid->Data2 =3D (UINT16)Data; - - // - // Data3 - // - PtrBuffer++; - PtrPosition =3D PtrBuffer; - while (*PtrBuffer !=3D L'\0') { - if (*PtrBuffer =3D=3D L'-') { - break; - } - PtrBuffer++; - } - if (*PtrBuffer =3D=3D L'\0') { - FreePool (Buffer); - return EFI_NOT_FOUND; - } - *PtrBuffer =3D L'\0'; - Data =3D StrHexToUintn (PtrPosition); - Guid->Data3 =3D (UINT16)Data; - - // - // Data4[0..1] - // - for ( Index =3D 0 ; Index < 2 ; Index++) { - PtrBuffer++; - if ((*PtrBuffer =3D=3D L'\0') || ( *(PtrBuffer + 1) =3D=3D L'\0')) { - FreePool (Buffer); - return EFI_NOT_FOUND; - } - Digits[0] =3D *PtrBuffer; - PtrBuffer++; - Digits[1] =3D *PtrBuffer; - Digits[2] =3D L'\0'; - Data =3D StrHexToUintn (Digits); - Guid->Data4[Index] =3D (UINT8)Data; - } - - // - // skip the '-' - // - PtrBuffer++; - if ((*PtrBuffer !=3D L'-' ) || ( *PtrBuffer =3D=3D L'\0')) { - return EFI_NOT_FOUND; - } - - // - // Data4[2..7] - // - for ( ; Index < 8; Index++) { - PtrBuffer++; - if ((*PtrBuffer =3D=3D L'\0') || ( *(PtrBuffer + 1) =3D=3D L'\0')) { - FreePool (Buffer); - return EFI_NOT_FOUND; - } - Digits[0] =3D *PtrBuffer; - PtrBuffer++; - Digits[1] =3D *PtrBuffer; - Digits[2] =3D L'\0'; - Data =3D StrHexToUintn (Digits); - Guid->Data4[Index] =3D (UINT8)Data; - } - - FreePool (Buffer); - =20 - return EFI_SUCCESS; -} - /** Worker function that prints an EFI_GUID into specified Buffer. =20 --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 14:36:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 148773908399687.73769856314584; Tue, 21 Feb 2017 20:51:23 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 190A38226D; Tue, 21 Feb 2017 20:51:02 -0800 (PST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 1344F82251 for ; Tue, 21 Feb 2017 20:51:00 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2017 20:50:59 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga001.jf.intel.com with ESMTP; 21 Feb 2017 20:50:59 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,192,1484035200"; d="scan'208";a="1100867173" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 22 Feb 2017 12:50:45 +0800 Message-Id: <20170222045047.558308-10-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20170222045047.558308-1-ruiyu.ni@intel.com> References: <20170222045047.558308-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 09/11] ShellPkg/Debug1CommandLib: Use StrToGuid/StrHexToBytes in BaseLib 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: , Cc: Jaben Carsey MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Jaben Carsey --- .../Library/UefiShellDebug1CommandsLib/DmpStore.c | 5 +- .../Library/UefiShellDebug1CommandsLib/SetVar.c | 10 +- .../UefiShellDebug1CommandsLib.c | 119 +----------------= ---- .../UefiShellDebug1CommandsLib.h | 32 +----- 4 files changed, 7 insertions(+), 159 deletions(-) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c b/Shell= Pkg/Library/UefiShellDebug1CommandsLib/DmpStore.c index bb2c0b9..e5b91ef 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/DmpStore.c @@ -2,7 +2,7 @@ Main file for DmpStore shell Debug1 function. =20 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -728,8 +728,7 @@ ShellCommandRunDmpStore ( if (!ShellCommandLineGetFlag(Package, L"-all")) { GuidStr =3D ShellCommandLineGetValue(Package, L"-guid"); if (GuidStr !=3D NULL) { - Status =3D ConvertStringToGuid(GuidStr, &GuidData); - if (EFI_ERROR(Status)) { + if (RETURN_ERROR (StrToGuid (GuidStr, &GuidData)) || (GuidStr[GU= ID_STRING_LENGTH] !=3D L'\0')) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV)= , gShellDebug1HiiHandle, L"dmpstore", GuidStr); =20 ShellStatus =3D SHELL_INVALID_PARAMETER; } diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c b/ShellPk= g/Library/UefiShellDebug1CommandsLib/SetVar.c index d98a346..7bd7b0f 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c @@ -2,7 +2,7 @@ Main file for SetVar shell Debug1 function. =20 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -120,8 +120,7 @@ ShellCommandRunSetVar ( CopyGuid(&Guid, &gEfiGlobalVariableGuid); } else { StringGuid =3D ShellCommandLineGetValue(Package, L"-guid"); - Status =3D ConvertStringToGuid(StringGuid, &Guid); - if (EFI_ERROR(Status)) { + if (RETURN_ERROR (StrToGuid (StringGuid, &Guid)) || (StringGuid[GU= ID_STRING_LENGTH] !=3D L'\0')) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), = gShellDebug1HiiHandle, L"setvar", StringGuid); =20 ShellStatus =3D SHELL_INVALID_PARAMETER; } @@ -207,10 +206,7 @@ ShellCommandRunSetVar ( if (Buffer =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; } else { - for (LoopVar =3D 0 ; LoopVar < (StrLen(Data) / 2) ; LoopVar+= +) { - ((UINT8*)Buffer)[LoopVar] =3D (UINT8)(HexCharToUintn(Data[= LoopVar*2]) * 16); - ((UINT8*)Buffer)[LoopVar] =3D (UINT8)(((UINT8*)Buffer)[Loo= pVar] + HexCharToUintn(Data[LoopVar*2+1])); - } + StrHexToBytes (Data, StrLen (Data), Buffer, StrLen (Data) / = 2); Status =3D gRT->SetVariable((CHAR16*)VariableName, &Guid, At= tributes, StrLen(Data) / 2, Buffer); } if (EFI_ERROR(Status)) { diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Com= mandsLib.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Com= mandsLib.c index 6ebf002..8e2141b 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.c @@ -1,7 +1,7 @@ /** @file Main file for NULL named library for debug1 profile shell command functi= ons. =20 - Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -172,123 +172,6 @@ GetSystemConfigurationTable ( } =20 /** - Convert a Unicode character to numerical value. - - This internal function only deal with Unicode character - which maps to a valid hexadecimal ASII character, i.e. - L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other - Unicode character, the value returned does not make sense. - - @param Char The character to convert. - - @return The numerical value converted. - -**/ -UINTN -HexCharToUintn ( - IN CHAR16 Char - ) -{ - if (Char >=3D L'0' && Char <=3D L'9') { - return Char - L'0'; - } - - return (UINTN) (10 + CharToUpper (Char) - L'A'); -} - -/** - Convert a string representation of a guid to a Guid value. - - @param[in] StringGuid The pointer to the string of a guid. - @param[in, out] Guid The pointer to the GUID structure to populate. - - @retval EFI_INVALID_PARAMETER A parameter was invalid. - @retval EFI_SUCCESS The conversion was successful. -**/ -EFI_STATUS -ConvertStringToGuid ( - IN CONST CHAR16 *StringGuid, - IN OUT EFI_GUID *Guid - ) -{ - CHAR16 *TempCopy; - CHAR16 *TempSpot; - CHAR16 *Walker; - UINT64 TempVal; - EFI_STATUS Status; - - if (StringGuid =3D=3D NULL) { - return (EFI_INVALID_PARAMETER); - } else if (StrLen(StringGuid) !=3D 36) { - return (EFI_INVALID_PARAMETER); - }=20 - TempCopy =3D NULL; - TempCopy =3D StrnCatGrow(&TempCopy, NULL, StringGuid, 0); - if (TempCopy =3D=3D NULL) { - return (EFI_OUT_OF_RESOURCES); - } - Walker =3D TempCopy; - TempSpot =3D StrStr(Walker, L"-"); - if (TempSpot !=3D NULL) { - *TempSpot =3D CHAR_NULL; - } - Status =3D ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE); - if (EFI_ERROR(Status)) { - FreePool(TempCopy); - return (Status); - } - Guid->Data1 =3D (UINT32)TempVal; - Walker +=3D 9; - TempSpot =3D StrStr(Walker, L"-"); - if (TempSpot !=3D NULL) { - *TempSpot =3D CHAR_NULL; - } - Status =3D ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE); - if (EFI_ERROR(Status)) { - FreePool(TempCopy); - return (Status); - } - Guid->Data2 =3D (UINT16)TempVal; - Walker +=3D 5; - TempSpot =3D StrStr(Walker, L"-"); - if (TempSpot !=3D NULL) { - *TempSpot =3D CHAR_NULL; - } - Status =3D ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE); - if (EFI_ERROR(Status)) { - FreePool(TempCopy); - return (Status); - } - Guid->Data3 =3D (UINT16)TempVal; - Walker +=3D 5; - Guid->Data4[0] =3D (UINT8)(HexCharToUintn(Walker[0]) * 16); - Guid->Data4[0] =3D (UINT8)(Guid->Data4[0]+ (UINT8)HexCharToUintn(Walker[= 1])); - Walker +=3D 2; - Guid->Data4[1] =3D (UINT8)(HexCharToUintn(Walker[0]) * 16); - Guid->Data4[1] =3D (UINT8)(Guid->Data4[1] + (UINT8)HexCharToUintn(Walker= [1])); - Walker +=3D 3; - Guid->Data4[2] =3D (UINT8)(HexCharToUintn(Walker[0]) * 16); - Guid->Data4[2] =3D (UINT8)(Guid->Data4[2] + (UINT8)HexCharToUintn(Walker= [1])); - Walker +=3D 2; - Guid->Data4[3] =3D (UINT8)(HexCharToUintn(Walker[0]) * 16); - Guid->Data4[3] =3D (UINT8)(Guid->Data4[3] + (UINT8)HexCharToUintn(Walker= [1])); - Walker +=3D 2; - Guid->Data4[4] =3D (UINT8)(HexCharToUintn(Walker[0]) * 16); - Guid->Data4[4] =3D (UINT8)(Guid->Data4[4] + (UINT8)HexCharToUintn(Walker= [1])); - Walker +=3D 2; - Guid->Data4[5] =3D (UINT8)(HexCharToUintn(Walker[0]) * 16); - Guid->Data4[5] =3D (UINT8)(Guid->Data4[5] + (UINT8)HexCharToUintn(Walker= [1])); - Walker +=3D 2; - Guid->Data4[6] =3D (UINT8)(HexCharToUintn(Walker[0]) * 16); - Guid->Data4[6] =3D (UINT8)(Guid->Data4[6] + (UINT8)HexCharToUintn(Walker= [1])); - Walker +=3D 2; - Guid->Data4[7] =3D (UINT8)(HexCharToUintn(Walker[0]) * 16); - Guid->Data4[7] =3D (UINT8)(Guid->Data4[7] + (UINT8)HexCharToUintn(Walker= [1])); - FreePool(TempCopy); - return (EFI_SUCCESS); -} - -/** Clear the line at the specified Row. =20 @param[in] Row The row number to be cleared ( start from = 1 ) diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Com= mandsLib.h b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Com= mandsLib.h index 52ea56a..80a8476 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.h +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLi= b.h @@ -1,7 +1,7 @@ /** @file Main file for NULL named library for Profile1 shell command functions. =20 - Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -77,36 +77,6 @@ GetSystemConfigurationTable ( ); =20 /** - Convert a string representation of a GUID to the GUID value. - - @param[in] StringGuid The pointer to the string containing a GUID pri= nted. - @param[in, out] Guid The pointer to the buffer to get the GUID value. -**/ -EFI_STATUS -ConvertStringToGuid ( - IN CONST CHAR16 *StringGuid, - IN OUT EFI_GUID *Guid - ); - -/** - Convert a Unicode character to numerical value. - - This internal function only deal with Unicode character - which maps to a valid hexadecimal ASII character, i.e. - L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other - Unicode character, the value returned does not make sense. - - @param Char The character to convert. - - @return The numerical value converted. - -**/ -UINTN -HexCharToUintn ( - IN CHAR16 Char - ); - -/** Function for 'setsize' command. =20 @param[in] ImageHandle Handle to the Image (NULL if Internal). --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 14:36:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487739087349816.2592372887577; Tue, 21 Feb 2017 20:51:27 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4B2C08225F; Tue, 21 Feb 2017 20:51:05 -0800 (PST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 0923882251 for ; Tue, 21 Feb 2017 20:51:01 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2017 20:51:00 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga001.jf.intel.com with ESMTP; 21 Feb 2017 20:51:00 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,192,1484035200"; d="scan'208";a="1100867180" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 22 Feb 2017 12:50:46 +0800 Message-Id: <20170222045047.558308-11-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20170222045047.558308-1-ruiyu.ni@intel.com> References: <20170222045047.558308-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 10/11] SignedCapsulePkg/IniParsingLib: Use AsciiStrToGuid in BaseLib 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: , Cc: Jiewen Yao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Jiewen Yao --- .../Library/IniParsingLib/IniParsingLib.c | 141 +----------------= ---- 1 file changed, 1 insertion(+), 140 deletions(-) diff --git a/SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.c b/Signe= dCapsulePkg/Library/IniParsingLib/IniParsingLib.c index 16e1349..e9c2cc5 100644 --- a/SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.c +++ b/SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.c @@ -862,144 +862,6 @@ UpdateGetProfileString ( } =20 /** - Converts a list of string to a specified buffer. - - @param[out] Buf The output buffer that contains the string. - @param[in] BufferLength The length of the buffer - @param[in] Str The input string that contains the hex number - - @retval EFI_SUCCESS The string was successfully converted to the buff= er. - -**/ -EFI_STATUS -AsciiStrToBuf ( - OUT UINT8 *Buf, - IN UINTN BufferLength, - IN CHAR8 *Str - ) -{ - UINTN Index; - UINTN StrLength; - UINT8 Digit; - UINT8 Byte; - - Digit =3D 0; - - // - // Two hex char make up one byte - // - StrLength =3D BufferLength * 2; - - for(Index =3D 0; Index < StrLength; Index++, Str++) { - - if ((*Str >=3D 'a') && (*Str <=3D 'f')) { - Digit =3D (UINT8) (*Str - 'a' + 0x0A); - } else if ((*Str >=3D 'A') && (*Str <=3D 'F')) { - Digit =3D (UINT8) (*Str - 'A' + 0x0A); - } else if ((*Str >=3D '0') && (*Str <=3D '9')) { - Digit =3D (UINT8) (*Str - '0'); - } else { - return EFI_INVALID_PARAMETER; - } - - // - // For odd characters, write the upper nibble for each buffer byte, - // and for even characters, the lower nibble. - // - if ((Index & 1) =3D=3D 0) { - Byte =3D (UINT8) (Digit << 4); - } else { - Byte =3D Buf[Index / 2]; - Byte &=3D 0xF0; - Byte =3D (UINT8) (Byte | Digit); - } - - Buf[Index / 2] =3D Byte; - } - - return EFI_SUCCESS; -} - -/** - Converts a string to GUID value. - Guid Format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - - @param[in] Str The registry format GUID string that contai= ns the GUID value. - @param[out] Guid A pointer to the converted GUID value. - - @retval EFI_SUCCESS The GUID string was successfully converted to th= e GUID value. - @retval EFI_UNSUPPORTED The input string is not in registry format. - @return others Some error occurred when converting part of GUID= value. - -**/ -EFI_STATUS -IniAsciiStrToGuid ( - IN CHAR8 *Str, - OUT EFI_GUID *Guid - ) -{ - // - // Get the first UINT32 data - // - Guid->Data1 =3D (UINT32) AsciiStrHexToUint64 (Str); - while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) { - Str ++; - } - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - - // - // Get the second UINT16 data - // - Guid->Data2 =3D (UINT16) AsciiStrHexToUint64 (Str); - while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) { - Str ++; - } - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - - // - // Get the third UINT16 data - // - Guid->Data3 =3D (UINT16) AsciiStrHexToUint64 (Str); - while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) { - Str ++; - } - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - - // - // Get the following 8 bytes data - // - AsciiStrToBuf (&Guid->Data4[0], 2, Str); - // - // Skip 2 byte hex chars - // - Str +=3D 2 * 2; - - if (IS_HYPHEN (*Str)) { - Str++; - } else { - return EFI_UNSUPPORTED; - } - AsciiStrToBuf (&Guid->Data4[2], 6, Str); - - return EFI_SUCCESS; -} - -/** Pre process config data buffer into Section entry list and Comment entry= list. =20 @param[in] DataBuffer Config raw file buffer. @@ -1261,8 +1123,7 @@ GetGuidFromDataFile ( if (!IsValidGuid(Value, AsciiStrLen(Value))) { return EFI_NOT_FOUND; } - Status =3D IniAsciiStrToGuid(Value, Guid); - if (EFI_ERROR (Status)) { + if (RETURN_ERROR (AsciiStrToGuid (Value, Guid))) { return EFI_NOT_FOUND; } return EFI_SUCCESS; --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Nov 2 14:36:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 148773909052229.22559395405301; Tue, 21 Feb 2017 20:51:30 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 89D2782270; Tue, 21 Feb 2017 20:51:05 -0800 (PST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 02F1982223 for ; Tue, 21 Feb 2017 20:51:01 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2017 20:51:01 -0800 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga001.jf.intel.com with ESMTP; 21 Feb 2017 20:51:00 -0800 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,192,1484035200"; d="scan'208";a="1100867186" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 22 Feb 2017 12:50:47 +0800 Message-Id: <20170222045047.558308-12-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20170222045047.558308-1-ruiyu.ni@intel.com> References: <20170222045047.558308-1-ruiyu.ni@intel.com> Subject: [edk2] [PATCH 11/11] MdeModulePkg/NetLib: Use StrToIpv4/6Address in BaseLib 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: , Cc: Siyuan Fu MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Siyuan Fu --- MdeModulePkg/Include/Library/NetLib.h | 5 +- MdeModulePkg/Library/DxeNetLib/DxeNetLib.c | 382 +++----------------------= ---- 2 files changed, 32 insertions(+), 355 deletions(-) diff --git a/MdeModulePkg/Include/Library/NetLib.h b/MdeModulePkg/Include/L= ibrary/NetLib.h index 09ead09..6773ed5 100644 --- a/MdeModulePkg/Include/Library/NetLib.h +++ b/MdeModulePkg/Include/Library/NetLib.h @@ -2,7 +2,7 @@ This library is only intended to be used by UEFI network stack modules. It provides basic functions for the UEFI network stack. =20 -Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2017, 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
@@ -1391,7 +1391,6 @@ NetLibAsciiStrToIp6 ( =20 @retval EFI_SUCCESS Converted to an IPv4 address successfully. @retval EFI_INVALID_PARAMETER The string is mal-formatted or Ip4Address= is NULL. - @retval EFI_OUT_OF_RESOURCES Failed to perform the operation due to la= ck of resources. =20 **/ EFI_STATUS @@ -1410,7 +1409,6 @@ NetLibStrToIp4 ( =20 @retval EFI_SUCCESS Converted to an IPv6 address successfully. @retval EFI_INVALID_PARAMETER The string is malformatted or Ip6Address = is NULL. - @retval EFI_OUT_OF_RESOURCES Failed to perform the operation due to a = lack of resources. =20 **/ EFI_STATUS @@ -1431,7 +1429,6 @@ NetLibStrToIp6 ( =20 @retval EFI_SUCCESS Converted to an IPv6 address successfull= y. @retval EFI_INVALID_PARAMETER The string is malformatted, or Ip6Address= is NULL. - @retval EFI_OUT_OF_RESOURCES Failed to perform the operation due to a = lack of resources. =20 **/ EFI_STATUS diff --git a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c b/MdeModulePkg/Libr= ary/DxeNetLib/DxeNetLib.c index 0a7117c..37b89f5 100644 --- a/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c +++ b/MdeModulePkg/Library/DxeNetLib/DxeNetLib.c @@ -1,7 +1,7 @@ /** @file Network library. =20 -Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2005 - 2017, 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 @@ -2709,63 +2709,15 @@ NetLibAsciiStrToIp4 ( OUT EFI_IPv4_ADDRESS *Ip4Address ) { - UINT8 Index; - CHAR8 *Ip4Str; - CHAR8 *TempStr; - UINTN NodeVal; + RETURN_STATUS Status; + CHAR8 *EndPointer; =20 - if ((String =3D=3D NULL) || (Ip4Address =3D=3D NULL)) { + Status =3D AsciiStrToIpv4Address (String, &EndPointer, Ip4Address, NULL); + if (RETURN_ERROR (Status) || (*EndPointer !=3D '\0')) { return EFI_INVALID_PARAMETER; + } else { + return EFI_SUCCESS; } - - Ip4Str =3D (CHAR8 *) String; - - for (Index =3D 0; Index < 4; Index++) { - TempStr =3D Ip4Str; - - while ((*Ip4Str !=3D '\0') && (*Ip4Str !=3D '.')) { - if (Index !=3D 3 && !NET_IS_DIGIT (*Ip4Str)) { - return EFI_INVALID_PARAMETER; - } - =20 - // - // Allow the IPv4 with prefix case, e.g. 192.168.10.10/24=20 - // - if (Index =3D=3D 3 && !NET_IS_DIGIT (*Ip4Str) && *Ip4Str !=3D '/') { - return EFI_INVALID_PARAMETER; - } - =20 - Ip4Str++; - } - - // - // The IPv4 address is X.X.X.X - // - if (*Ip4Str =3D=3D '.') { - if (Index =3D=3D 3) { - return EFI_INVALID_PARAMETER; - } - } else { - if (Index !=3D 3) { - return EFI_INVALID_PARAMETER; - } - } - - // - // Convert the string to IPv4 address. AsciiStrDecimalToUintn stops at= the - // first character that is not a valid decimal character, '.' or '\0' = here. - // - NodeVal =3D AsciiStrDecimalToUintn (TempStr); - if (NodeVal > 0xFF) { - return EFI_INVALID_PARAMETER; - } - - Ip4Address->Addr[Index] =3D (UINT8) NodeVal; - - Ip4Str++; - } - - return EFI_SUCCESS; } =20 =20 @@ -2787,193 +2739,15 @@ NetLibAsciiStrToIp6 ( OUT EFI_IPv6_ADDRESS *Ip6Address ) { - UINT8 Index; - CHAR8 *Ip6Str; - CHAR8 *TempStr; - CHAR8 *TempStr2; - UINT8 NodeCnt; - UINT8 TailNodeCnt; - UINT8 AllowedCnt; - UINTN NodeVal; - BOOLEAN Short; - BOOLEAN Update; - BOOLEAN LeadZero; - UINT8 LeadZeroCnt; - UINT8 Cnt; - - if ((String =3D=3D NULL) || (Ip6Address =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - Ip6Str =3D (CHAR8 *) String; - AllowedCnt =3D 6; - LeadZeroCnt =3D 0; - - // - // An IPv6 address leading with : looks strange. - // - if (*Ip6Str =3D=3D ':') { - if (*(Ip6Str + 1) !=3D ':') { - return EFI_INVALID_PARAMETER; - } else { - AllowedCnt =3D 7; - } - } + RETURN_STATUS Status; + CHAR8 *EndPointer; =20 - ZeroMem (Ip6Address, sizeof (EFI_IPv6_ADDRESS)); - - NodeCnt =3D 0; - TailNodeCnt =3D 0; - Short =3D FALSE; - Update =3D FALSE; - LeadZero =3D FALSE; - - for (Index =3D 0; Index < 15; Index =3D (UINT8) (Index + 2)) { - TempStr =3D Ip6Str; - - while ((*Ip6Str !=3D '\0') && (*Ip6Str !=3D ':')) { - if (Index !=3D 14 && !NET_IS_HEX (*Ip6Str)) { - return EFI_INVALID_PARAMETER; - } - =20 - // - // Allow the IPv6 with prefix case, e.g. 2000:aaaa::10/24=20 - // - if (Index =3D=3D 14 && !NET_IS_HEX (*Ip6Str) && *Ip6Str !=3D '/') { - return EFI_INVALID_PARAMETER; - } - =20 - Ip6Str++; - } - - if ((*Ip6Str =3D=3D '\0') && (Index !=3D 14)) { - return EFI_INVALID_PARAMETER; - } - - if (*Ip6Str =3D=3D ':') { - if (*(Ip6Str + 1) =3D=3D ':') { - if ((NodeCnt > 6) ||=20 - ((*(Ip6Str + 2) !=3D '\0') && (AsciiStrHexToUintn (Ip6Str + 2)= =3D=3D 0))) { - // - // ::0 looks strange. report error to user. - // - return EFI_INVALID_PARAMETER; - } - if ((NodeCnt =3D=3D 6) && (*(Ip6Str + 2) !=3D '\0') &&=20 - (AsciiStrHexToUintn (Ip6Str + 2) !=3D 0)) { - return EFI_INVALID_PARAMETER; - } - - // - // Skip the abbreviation part of IPv6 address. - // - TempStr2 =3D Ip6Str + 2; - while ((*TempStr2 !=3D '\0')) { - if (*TempStr2 =3D=3D ':') { - if (*(TempStr2 + 1) =3D=3D ':') { - // - // :: can only appear once in IPv6 address. - // - return EFI_INVALID_PARAMETER; - } - - TailNodeCnt++; - if (TailNodeCnt >=3D (AllowedCnt - NodeCnt)) { - // - // :: indicates one or more groups of 16 bits of zeros. - // - return EFI_INVALID_PARAMETER; - } - } - - TempStr2++; - } - - Short =3D TRUE; - Update =3D TRUE; - - Ip6Str =3D Ip6Str + 2; - } else { - if (*(Ip6Str + 1) =3D=3D '\0') { - return EFI_INVALID_PARAMETER; - } - Ip6Str++; - NodeCnt++; - if ((Short && (NodeCnt > 6)) || (!Short && (NodeCnt > 7))) { - // - // There are more than 8 groups of 16 bits of zeros. - // - return EFI_INVALID_PARAMETER; - } - } - } - - // - // Convert the string to IPv6 address. AsciiStrHexToUintn stops at the= first - // character that is not a valid hexadecimal character, ':' or '\0' he= re. - // - NodeVal =3D AsciiStrHexToUintn (TempStr); - if ((NodeVal > 0xFFFF) || (Index > 14)) { - return EFI_INVALID_PARAMETER; - } - if (NodeVal !=3D 0) { - if ((*TempStr =3D=3D '0') &&=20 - ((*(TempStr + 2) =3D=3D ':') || (*(TempStr + 3) =3D=3D ':') ||=20 - (*(TempStr + 2) =3D=3D '\0') || (*(TempStr + 3) =3D=3D '\0'))) { - return EFI_INVALID_PARAMETER; - } - if ((*TempStr =3D=3D '0') && (*(TempStr + 4) !=3D '\0') &&=20 - (*(TempStr + 4) !=3D ':')) {=20 - return EFI_INVALID_PARAMETER; - } - } else { - if (((*TempStr =3D=3D '0') && (*(TempStr + 1) =3D=3D '0') &&=20 - ((*(TempStr + 2) =3D=3D ':') || (*(TempStr + 2) =3D=3D '\0'))) || - ((*TempStr =3D=3D '0') && (*(TempStr + 1) =3D=3D '0') && (*(Tem= pStr + 2) =3D=3D '0') &&=20 - ((*(TempStr + 3) =3D=3D ':') || (*(TempStr + 3) =3D=3D '\0')))) { - return EFI_INVALID_PARAMETER; - } - } - - Cnt =3D 0; - while ((TempStr[Cnt] !=3D ':') && (TempStr[Cnt] !=3D '\0')) { - Cnt++;=20 - } - if (LeadZeroCnt =3D=3D 0) { - if ((Cnt =3D=3D 4) && (*TempStr =3D=3D '0')) { - LeadZero =3D TRUE; - LeadZeroCnt++; - } - if ((Cnt !=3D 0) && (Cnt < 4)) { - LeadZero =3D FALSE; - LeadZeroCnt++; - } - } else { - if ((Cnt =3D=3D 4) && (*TempStr =3D=3D '0') && !LeadZero) { - return EFI_INVALID_PARAMETER; - } - if ((Cnt !=3D 0) && (Cnt < 4) && LeadZero) { - return EFI_INVALID_PARAMETER; - } - }=20 - - Ip6Address->Addr[Index] =3D (UINT8) (NodeVal >> 8); - Ip6Address->Addr[Index + 1] =3D (UINT8) (NodeVal & 0xFF); - - // - // Skip the groups of zeros by :: - // - if (Short && Update) { - Index =3D (UINT8) (16 - (TailNodeCnt + 2) * 2); - Update =3D FALSE; - } - } - - if ((!Short && Index !=3D 16) || (*Ip6Str !=3D '\0')) { + Status =3D AsciiStrToIpv6Address (String, &EndPointer, Ip6Address, NULL); + if (RETURN_ERROR (Status) || (*EndPointer !=3D '\0')) { return EFI_INVALID_PARAMETER; + } else { + return EFI_SUCCESS; } - - return EFI_SUCCESS; } =20 =20 @@ -2985,7 +2759,6 @@ NetLibAsciiStrToIp6 ( =20 @retval EFI_SUCCESS Convert to IPv4 address successfully. @retval EFI_INVALID_PARAMETER The string is mal-formated or Ip4Address = is NULL. - @retval EFI_OUT_OF_RESOURCES Fail to perform the operation due to lack= of resource. =20 **/ EFI_STATUS @@ -2995,27 +2768,15 @@ NetLibStrToIp4 ( OUT EFI_IPv4_ADDRESS *Ip4Address ) { - CHAR8 *Ip4Str; - UINTN StringSize; - EFI_STATUS Status; + RETURN_STATUS Status; + CHAR16 *EndPointer; =20 - if ((String =3D=3D NULL) || (Ip4Address =3D=3D NULL)) { + Status =3D StrToIpv4Address (String, &EndPointer, Ip4Address, NULL); + if (RETURN_ERROR (Status) || (*EndPointer !=3D L'\0')) { return EFI_INVALID_PARAMETER; + } else { + return EFI_SUCCESS; } - - StringSize =3D StrLen (String) + 1; - Ip4Str =3D (CHAR8 *) AllocatePool (StringSize * sizeof (CHAR8)); - if (Ip4Str =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - UnicodeStrToAsciiStrS (String, Ip4Str, StringSize); - - Status =3D NetLibAsciiStrToIp4 (Ip4Str, Ip4Address); - - FreePool (Ip4Str); - - return Status; } =20 =20 @@ -3028,7 +2789,6 @@ NetLibStrToIp4 ( =20 @retval EFI_SUCCESS Convert to IPv6 address successfully. @retval EFI_INVALID_PARAMETER The string is mal-formated or Ip6Address = is NULL. - @retval EFI_OUT_OF_RESOURCES Fail to perform the operation due to lack= of resource. =20 **/ EFI_STATUS @@ -3038,27 +2798,15 @@ NetLibStrToIp6 ( OUT EFI_IPv6_ADDRESS *Ip6Address ) { - CHAR8 *Ip6Str; - UINTN StringSize; - EFI_STATUS Status; + RETURN_STATUS Status; + CHAR16 *EndPointer; =20 - if ((String =3D=3D NULL) || (Ip6Address =3D=3D NULL)) { + Status =3D StrToIpv6Address (String, &EndPointer, Ip6Address, NULL); + if (RETURN_ERROR (Status) || (*EndPointer !=3D L'\0')) { return EFI_INVALID_PARAMETER; + } else { + return EFI_SUCCESS; } - - StringSize =3D StrLen (String) + 1; - Ip6Str =3D (CHAR8 *) AllocatePool (StringSize * sizeof (CHAR8)); - if (Ip6Str =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - UnicodeStrToAsciiStrS (String, Ip6Str, StringSize); - - Status =3D NetLibAsciiStrToIp6 (Ip6Str, Ip6Address); - - FreePool (Ip6Str); - - return Status; } =20 /** @@ -3072,7 +2820,6 @@ NetLibStrToIp6 ( =20 @retval EFI_SUCCESS Convert to IPv6 address successfully. @retval EFI_INVALID_PARAMETER The string is mal-formated or Ip6Address = is NULL. - @retval EFI_OUT_OF_RESOURCES Fail to perform the operation due to lack= of resource. =20 **/ EFI_STATUS @@ -3083,82 +2830,15 @@ NetLibStrToIp6andPrefix ( OUT UINT8 *PrefixLength ) { - CHAR8 *Ip6Str; - UINTN StringSize; - CHAR8 *PrefixStr; - CHAR8 *TempStr; - EFI_STATUS Status; - UINT8 Length; - - if ((String =3D=3D NULL) || (Ip6Address =3D=3D NULL) || (PrefixLength = =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - StringSize =3D StrLen (String) + 1; - Ip6Str =3D (CHAR8 *) AllocatePool (StringSize * sizeof (CHAR8)); - if (Ip6Str =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - UnicodeStrToAsciiStrS (String, Ip6Str, StringSize); - - // - // Get the sub string describing prefix length. - // - TempStr =3D Ip6Str; - while (*TempStr !=3D '\0' && (*TempStr !=3D '/')) { - TempStr++; - } + RETURN_STATUS Status; + CHAR16 *EndPointer; =20 - if (*TempStr =3D=3D '/') { - PrefixStr =3D TempStr + 1; + Status =3D StrToIpv6Address (String, &EndPointer, Ip6Address, PrefixLeng= th); + if (RETURN_ERROR (Status) || (*EndPointer !=3D L'\0')) { + return EFI_INVALID_PARAMETER; } else { - PrefixStr =3D NULL; - } - - // - // Get the sub string describing IPv6 address and convert it. - // - *TempStr =3D '\0'; - - Status =3D NetLibAsciiStrToIp6 (Ip6Str, Ip6Address); - if (EFI_ERROR (Status)) { - goto Exit; - } - - // - // If input string doesn't indicate the prefix length, return 0xff. - // - Length =3D 0xFF; - - // - // Convert the string to prefix length - // - if (PrefixStr !=3D NULL) { - - Status =3D EFI_INVALID_PARAMETER; - Length =3D 0; - while (*PrefixStr !=3D '\0') { - if (NET_IS_DIGIT (*PrefixStr)) { - Length =3D (UINT8) (Length * 10 + (*PrefixStr - '0')); - if (Length > IP6_PREFIX_MAX) { - goto Exit; - } - } else { - goto Exit; - } - - PrefixStr++; - } + return EFI_SUCCESS; } - - *PrefixLength =3D Length; - Status =3D EFI_SUCCESS; - -Exit: - - FreePool (Ip6Str); - return Status; } =20 /** --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel