]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c
MdeModulePkg: Replace UnicodeStrToAsciiStr/AsciiStrToUnicodeStr
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / ConfigKeywordHandler.c
index 5e7aca96816e4d8fce42dcbe30b86f4f84c19090..03f814119993f3f57a77e0906584d5a85392b61d 100644 (file)
@@ -178,6 +178,7 @@ ExtractNameSpace (
   )\r
 {\r
   CHAR16    *TmpPtr;\r
+  UINTN     NameSpaceSize;\r
 \r
   ASSERT (NameSpace != NULL);\r
 \r
@@ -218,11 +219,12 @@ ExtractNameSpace (
   // Input NameSpace is unicode string. The language in String package is ascii string.\r
   // Here will convert the unicode string to ascii and save it.\r
   //\r
-  *NameSpace = AllocatePool (StrLen (String) + 1);\r
+  NameSpaceSize = StrLen (String) + 1;\r
+  *NameSpace = AllocatePool (NameSpaceSize);\r
   if (*NameSpace == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  UnicodeStrToAsciiStr (String, *NameSpace);\r
+  UnicodeStrToAsciiStrS (String, *NameSpace, NameSpaceSize);\r
 \r
   if (TmpPtr != NULL) {\r
     *TmpPtr = L'&'; \r
@@ -779,6 +781,7 @@ GetStringIdFromString (
   UINTN                                StringSize;\r
   CHAR16                               *String;\r
   CHAR8                                *AsciiKeywordValue;\r
+  UINTN                                KeywordValueSize;\r
   EFI_STATUS                           Status;\r
 \r
   ASSERT (StringPackage != NULL && KeywordValue != NULL && StringId != NULL);\r
@@ -794,11 +797,12 @@ GetStringIdFromString (
   //\r
   // Make a ascii keyword value for later use.\r
   //\r
-  AsciiKeywordValue = AllocatePool (StrLen (KeywordValue) + 1);\r
+  KeywordValueSize = StrLen (KeywordValue) + 1;\r
+  AsciiKeywordValue = AllocatePool (KeywordValueSize);\r
   if (AsciiKeywordValue == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  UnicodeStrToAsciiStr(KeywordValue, AsciiKeywordValue);\r
+  UnicodeStrToAsciiStrS (KeywordValue, AsciiKeywordValue, KeywordValueSize);\r
 \r
   while (*BlockHdr != EFI_HII_SIBT_END) {\r
     switch (*BlockHdr) {\r
@@ -1065,11 +1069,12 @@ GetNextStringId (
       StringTextPtr = BlockHdr + Offset;\r
       \r
       if (FindString) {\r
-        *KeywordValue = AllocatePool (AsciiStrSize ((CHAR8 *) StringTextPtr) * sizeof (CHAR16));\r
+        StringSize = AsciiStrSize ((CHAR8 *) StringTextPtr);\r
+        *KeywordValue = AllocatePool (StringSize * sizeof (CHAR16));\r
         if (*KeywordValue == NULL) {\r
           return 0;\r
         }\r
-        AsciiStrToUnicodeStr ((CHAR8 *) StringTextPtr, *KeywordValue);\r
+        AsciiStrToUnicodeStrS ((CHAR8 *) StringTextPtr, *KeywordValue, StringSize);\r
         return CurrentStringId;\r
       } else if (CurrentStringId == StringId) {\r
         FindString = TRUE;\r
@@ -1084,11 +1089,12 @@ GetNextStringId (
       StringTextPtr = BlockHdr + Offset;\r
       \r
       if (FindString) {\r
-        *KeywordValue = AllocatePool (AsciiStrSize ((CHAR8 *) StringTextPtr) * sizeof (CHAR16));\r
+        StringSize = AsciiStrSize ((CHAR8 *) StringTextPtr);\r
+        *KeywordValue = AllocatePool (StringSize * sizeof (CHAR16));\r
         if (*KeywordValue == NULL) {\r
           return 0;\r
         }\r
-        AsciiStrToUnicodeStr ((CHAR8 *) StringTextPtr, *KeywordValue);\r
+        AsciiStrToUnicodeStrS ((CHAR8 *) StringTextPtr, *KeywordValue, StringSize);\r
         return CurrentStringId;\r
       } else if (CurrentStringId == StringId) {\r
         FindString = TRUE;\r
@@ -1105,11 +1111,12 @@ GetNextStringId (
 \r
       for (Index = 0; Index < StringCount; Index++) {\r
         if (FindString) {\r
-          *KeywordValue = AllocatePool (AsciiStrSize ((CHAR8 *) StringTextPtr) * sizeof (CHAR16));\r
+          StringSize = AsciiStrSize ((CHAR8 *) StringTextPtr);\r
+          *KeywordValue = AllocatePool (StringSize * sizeof (CHAR16));\r
           if (*KeywordValue == NULL) {\r
             return 0;\r
           }\r
-          AsciiStrToUnicodeStr ((CHAR8 *) StringTextPtr, *KeywordValue);\r
+          AsciiStrToUnicodeStrS ((CHAR8 *) StringTextPtr, *KeywordValue, StringSize);\r
           return CurrentStringId;\r
         } else if (CurrentStringId == StringId) {\r
           FindString = TRUE;\r
@@ -1132,11 +1139,12 @@ GetNextStringId (
 \r
       for (Index = 0; Index < StringCount; Index++) {\r
         if (FindString) {\r
-          *KeywordValue = AllocatePool (AsciiStrSize ((CHAR8 *) StringTextPtr) * sizeof (CHAR16));\r
+          StringSize = AsciiStrSize ((CHAR8 *) StringTextPtr);\r
+          *KeywordValue = AllocatePool (StringSize * sizeof (CHAR16));\r
           if (*KeywordValue == NULL) {\r
             return 0;\r
           }\r
-          AsciiStrToUnicodeStr ((CHAR8 *) StringTextPtr, *KeywordValue);\r
+          AsciiStrToUnicodeStrS ((CHAR8 *) StringTextPtr, *KeywordValue, StringSize);\r
           return CurrentStringId;\r
         } else if (CurrentStringId == StringId) {\r
           FindString = TRUE;\r
@@ -1670,6 +1678,7 @@ ConstructConfigHdr (
   UINT8                     *Buffer;\r
   CHAR16                    *Name;\r
   CHAR8                     *AsciiName;\r
+  UINTN                     NameSize;\r
   EFI_GUID                  *Guid;\r
   UINTN                     MaxLen;\r
 \r
@@ -1699,9 +1708,10 @@ ConstructConfigHdr (
   }\r
 \r
   if (AsciiName != NULL) {\r
-    Name = AllocateZeroPool (AsciiStrSize (AsciiName) * 2);\r
+    NameSize = AsciiStrSize (AsciiName);\r
+    Name = AllocateZeroPool (NameSize * sizeof (CHAR16));\r
     ASSERT (Name != NULL);\r
-    AsciiStrToUnicodeStr(AsciiName, Name);\r
+    AsciiStrToUnicodeStrS (AsciiName, Name, NameSize);\r
   } else {\r
     Name = NULL;\r
   }\r
@@ -2375,6 +2385,7 @@ GenerateKeywordResp (
   CHAR16    *RespStr;\r
   CHAR16    *PathHdr;\r
   CHAR16    *UnicodeNameSpace;\r
+  UINTN     NameSpaceLength;\r
 \r
   ASSERT ((NameSpace != NULL) && (DevicePath != NULL) && (KeywordData != NULL) && (ValueStr != NULL) && (KeywordResp != NULL));\r
 \r
@@ -2385,12 +2396,13 @@ GenerateKeywordResp (
   // 1.1 NameSpaceId size.\r
   // 'NAMESPACE='<String>\r
   //\r
-  RespStrLen = 10 + AsciiStrLen (NameSpace);\r
-  UnicodeNameSpace = AllocatePool ((AsciiStrLen (NameSpace) + 1) * sizeof (CHAR16));\r
+  NameSpaceLength = AsciiStrLen (NameSpace);\r
+  RespStrLen = 10 + NameSpaceLength;\r
+  UnicodeNameSpace = AllocatePool ((NameSpaceLength + 1) * sizeof (CHAR16));\r
   if (UnicodeNameSpace == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  AsciiStrToUnicodeStr(NameSpace, UnicodeNameSpace);\r
+  AsciiStrToUnicodeStrS (NameSpace, UnicodeNameSpace, NameSpaceLength + 1);\r
 \r
   //\r
   // 1.2 PathHdr size.\r