]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SignedCapsulePkg/Library/IniParsingLib/IniParsingLib.c
SignedCapsulePkg: Fix various typos
[mirror_edk2.git] / SignedCapsulePkg / Library / IniParsingLib / IniParsingLib.c
index 5c975f7ca4a1a3ec17c13fe9bba1a97b89fbb851..bea45e0d3be3f0f8c662c46d85436e9246066101 100644 (file)
@@ -14,7 +14,7 @@
          3.1) an ASCII String. The valid format is [A-Za-z0-9_]+\r
          3.2) a GUID. The valid format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, where x is [A-Fa-f0-9]\r
          3.3) a decimal value. The valid format is [0-9]+\r
-         3.4) a heximal value. The valid format is 0x[A-Fa-f0-9]+\r
+         3.4) a hexadecimal value. The valid format is 0x[A-Fa-f0-9]+\r
       4) '#' or ';' can be used as comment at anywhere.\r
       5) TAB(0x20) or SPACE(0x9) can be used as separator.\r
       6) LF(\n, 0xA) or CR(\r, 0xD) can be used as line break.\r
   OpenIniFile(), PreProcessDataFile(), ProfileGetSection(), ProfileGetEntry()\r
   will receive untrusted input and do basic validation.\r
 \r
-  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>\r
 \r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions\r
-  of the BSD License which accompanies this distribution.  The\r
-  full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -50,8 +43,8 @@
 // This is default allocation. Reallocation will happen if it is not enough.\r
 #define MAX_LINE_LENGTH           512\r
 \r
-typedef struct _SECTION_ITEM SECTION_ITEM;\r
-struct _SECTION_ITEM {\r
+typedef struct _INI_SECTION_ITEM SECTION_ITEM;\r
+struct _INI_SECTION_ITEM {\r
   CHAR8                           *PtrSection;\r
   UINTN                           SecNameLen;\r
   CHAR8                           *PtrEntry;\r
@@ -59,8 +52,8 @@ struct _SECTION_ITEM {
   SECTION_ITEM                    *PtrNext;\r
 };\r
 \r
-typedef struct _COMMENT_LINE COMMENT_LINE;\r
-struct _COMMENT_LINE {\r
+typedef struct _INI_COMMENT_LINE COMMENT_LINE;\r
+struct _INI_COMMENT_LINE {\r
   CHAR8                           *PtrComment;\r
   COMMENT_LINE                    *PtrNext;\r
 };\r
@@ -172,13 +165,13 @@ IsValidDecimalString (
 }\r
 \r
 /**\r
-  Return if the heximal string is valid.\r
+  Return if the hexadecimal string is valid.\r
 \r
-  @param[in] Hex     The heximal string to be checked.\r
-  @param[in] Length  The length of heximal string in bytes.\r
+  @param[in] Hex     The hexadecimal string to be checked.\r
+  @param[in] Length  The length of hexadecimal string in bytes.\r
 \r
-  @retval TRUE   The heximal string is valid.\r
-  @retval FALSE  The heximal string is invalid.\r
+  @retval TRUE   The hexadecimal string is valid.\r
+  @retval FALSE  The hexadecimal string is invalid.\r
 **/\r
 BOOLEAN\r
 IsValidHexString (\r
@@ -395,7 +388,7 @@ ProfileGetLine (
 /**\r
   Trim Buffer by removing all CR, LF, TAB, and SPACE chars in its head and tail.\r
 \r
-  @param[in, out] Buffer          On input,  buffer data to be trimed.\r
+  @param[in, out] Buffer          On input,  buffer data to be trimmed.\r
                                   On output, the trimmed buffer.\r
   @param[in, out] BufferSize      On input,  size of original buffer data.\r
                                   On output, size of the trimmed buffer.\r
@@ -861,144 +854,6 @@ UpdateGetProfileString (
   return EFI_SUCCESS;\r
 }\r
 \r
-/**\r
-  Converts a list of string to a specified buffer.\r
-\r
-  @param[out] Buf             The output buffer that contains the string.\r
-  @param[in]  BufferLength    The length of the buffer\r
-  @param[in]  Str             The input string that contains the hex number\r
-\r
-  @retval EFI_SUCCESS    The string was successfully converted to the buffer.\r
-\r
-**/\r
-EFI_STATUS\r
-AsciiStrToBuf (\r
-  OUT UINT8    *Buf,\r
-  IN  UINTN    BufferLength,\r
-  IN  CHAR8    *Str\r
-  )\r
-{\r
-  UINTN       Index;\r
-  UINTN       StrLength;\r
-  UINT8       Digit;\r
-  UINT8       Byte;\r
-\r
-  Digit = 0;\r
-\r
-  //\r
-  // Two hex char make up one byte\r
-  //\r
-  StrLength = BufferLength * 2;\r
-\r
-  for(Index = 0; Index < StrLength; Index++, Str++) {\r
-\r
-    if ((*Str >= 'a') && (*Str <= 'f')) {\r
-      Digit = (UINT8) (*Str - 'a' + 0x0A);\r
-    } else if ((*Str >= 'A') && (*Str <= 'F')) {\r
-      Digit = (UINT8) (*Str - 'A' + 0x0A);\r
-    } else if ((*Str >= '0') && (*Str <= '9')) {\r
-      Digit = (UINT8) (*Str - '0');\r
-    } else {\r
-      return EFI_INVALID_PARAMETER;\r
-    }\r
-\r
-    //\r
-    // For odd characters, write the upper nibble for each buffer byte,\r
-    // and for even characters, the lower nibble.\r
-    //\r
-    if ((Index & 1) == 0) {\r
-      Byte = (UINT8) (Digit << 4);\r
-    } else {\r
-      Byte = Buf[Index / 2];\r
-      Byte &= 0xF0;\r
-      Byte = (UINT8) (Byte | Digit);\r
-    }\r
-\r
-    Buf[Index / 2] = Byte;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Converts a string to GUID value.\r
-  Guid Format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\r
-\r
-  @param[in]  Str              The registry format GUID string that contains the GUID value.\r
-  @param[out] Guid             A pointer to the converted GUID value.\r
-\r
-  @retval EFI_SUCCESS     The GUID string was successfully converted to the GUID value.\r
-  @retval EFI_UNSUPPORTED The input string is not in registry format.\r
-  @return others          Some error occurred when converting part of GUID value.\r
-\r
-**/\r
-EFI_STATUS\r
-AsciiStrToGuid (\r
-  IN  CHAR8    *Str,\r
-  OUT EFI_GUID *Guid\r
-  )\r
-{\r
-  //\r
-  // Get the first UINT32 data\r
-  //\r
-  Guid->Data1 = (UINT32) AsciiStrHexToUint64  (Str);\r
-  while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {\r
-    Str ++;\r
-  }\r
-\r
-  if (IS_HYPHEN (*Str)) {\r
-    Str++;\r
-  } else {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  //\r
-  // Get the second UINT16 data\r
-  //\r
-  Guid->Data2 = (UINT16) AsciiStrHexToUint64  (Str);\r
-  while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {\r
-    Str ++;\r
-  }\r
-\r
-  if (IS_HYPHEN (*Str)) {\r
-    Str++;\r
-  } else {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  //\r
-  // Get the third UINT16 data\r
-  //\r
-  Guid->Data3 = (UINT16) AsciiStrHexToUint64  (Str);\r
-  while (!IS_HYPHEN (*Str) && !IS_NULL (*Str)) {\r
-    Str ++;\r
-  }\r
-\r
-  if (IS_HYPHEN (*Str)) {\r
-    Str++;\r
-  } else {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  //\r
-  // Get the following 8 bytes data\r
-  //\r
-  AsciiStrToBuf (&Guid->Data4[0], 2, Str);\r
-  //\r
-  // Skip 2 byte hex chars\r
-  //\r
-  Str += 2 * 2;\r
-\r
-  if (IS_HYPHEN (*Str)) {\r
-    Str++;\r
-  } else {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-  AsciiStrToBuf (&Guid->Data4[2], 6, Str);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
 /**\r
   Pre process config data buffer into Section entry list and Comment entry list.\r
 \r
@@ -1243,6 +1098,7 @@ GetGuidFromDataFile (
 {\r
   CHAR8                                 *Value;\r
   EFI_STATUS                            Status;\r
+  RETURN_STATUS                         RStatus;\r
 \r
   if (Context == NULL || SectionName == NULL || EntryName == NULL || Guid == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1258,11 +1114,8 @@ GetGuidFromDataFile (
     return EFI_NOT_FOUND;\r
   }\r
   ASSERT (Value != NULL);\r
-  if (!IsValidGuid(Value, AsciiStrLen(Value))) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-  Status = AsciiStrToGuid(Value, Guid);\r
-  if (EFI_ERROR (Status)) {\r
+  RStatus = AsciiStrToGuid (Value, Guid);\r
+  if (RETURN_ERROR (RStatus) || (Value[GUID_STRING_LENGTH] != '\0')) {\r
     return EFI_NOT_FOUND;\r
   }\r
   return EFI_SUCCESS;\r
@@ -1313,14 +1166,14 @@ GetDecimalUintnFromDataFile (
 }\r
 \r
 /**\r
-  Get section entry heximal UINTN value.\r
+  Get section entry hexadecimal UINTN value.\r
 \r
   @param[in]  Context         INI Config file context.\r
   @param[in]  SectionName     Section name.\r
   @param[in]  EntryName       Section entry name.\r
-  @param[out] Data            Point to the got heximal UINTN value.\r
+  @param[out] Data            Point to the got hexadecimal UINTN value.\r
 \r
-  @retval EFI_SUCCESS    Section entry heximal UINTN value is got.\r
+  @retval EFI_SUCCESS    Section entry hexadecimal UINTN value is got.\r
   @retval EFI_NOT_FOUND  Section is not found.\r
 **/\r
 EFI_STATUS\r
@@ -1357,14 +1210,14 @@ GetHexUintnFromDataFile (
 }\r
 \r
 /**\r
-  Get section entry heximal UINT64 value.\r
+  Get section entry hexadecimal UINT64 value.\r
 \r
   @param[in]  Context         INI Config file context.\r
   @param[in]  SectionName     Section name.\r
   @param[in]  EntryName       Section entry name.\r
-  @param[out] Data            Point to the got heximal UINT64 value.\r
+  @param[out] Data            Point to the got hexadecimal UINT64 value.\r
 \r
-  @retval EFI_SUCCESS    Section entry heximal UINT64 value is got.\r
+  @retval EFI_SUCCESS    Section entry hexadecimal UINT64 value is got.\r
   @retval EFI_NOT_FOUND  Section is not found.\r
 **/\r
 EFI_STATUS\r