/** @file\r
Implementation of interfaces function for EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL.\r
\r
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
@param NextString string follow the possible PathHdr string.\r
\r
@retval EFI_INVALID_PARAMETER The device path is not valid or the incoming parameter is invalid.\r
- @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures.\r
+ @retval EFI_OUT_OF_RESOURCES Lake of resources to store necessary structures.\r
@retval EFI_SUCCESS The device path is retrieved and translated to binary format.\r
The Input string not include PathHdr section.\r
\r
)\r
{\r
CHAR16 *TmpPtr;\r
+ UINTN NameSpaceSize;\r
\r
ASSERT (NameSpace != NULL);\r
\r
// 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
\r
@param String KeywordRequestformat string.\r
@param Keyword return the extract keyword string.\r
- @param NextString return the next string follow this keyword sectin.\r
+ @param NextString return the next string follow this keyword section.\r
\r
@retval EFI_SUCCESS Success to get the keyword string.\r
- @retval EFI_INVALID_PARAMETER Parsr the input string return error.\r
+ @retval EFI_INVALID_PARAMETER Parse the input string return error.\r
\r
**/\r
EFI_STATUS\r
\r
@param String KeywordRequestformat string.\r
@param Value return the extract value string.\r
- @param NextString return the next string follow this keyword sectin.\r
+ @param NextString return the next string follow this keyword section.\r
\r
@retval EFI_SUCCESS Success to get the keyword string.\r
- @retval EFI_INVALID_PARAMETER Parsr the input string return error.\r
+ @retval EFI_INVALID_PARAMETER Parse the input string return error.\r
\r
**/\r
EFI_STATUS\r
\r
@param String KeywordRequestformat string.\r
@param FilterFlags return the filter condition.\r
- @param NextString return the next string follow this keyword sectin.\r
+ @param NextString return the next string follow this keyword section.\r
\r
@retval EFI_SUCCESS Success to get the keyword string.\r
- @retval EFI_INVALID_PARAMETER Parsr the input string return error.\r
+ @retval EFI_INVALID_PARAMETER Parse the input string return error.\r
\r
**/\r
BOOLEAN\r
String = KeywordPtr;\r
} else {\r
//\r
- // Only has paltform defined filter section, just skip it.\r
+ // Only has platform defined filter section, just skip it.\r
//\r
String += StrLen (String);\r
}\r
\r
This is a internal function.\r
\r
- @param OpCodeData The questin binary ifr data.\r
+ @param OpCodeData The question binary ifr data.\r
@param KeywordRequest KeywordRequestformat string.\r
- @param NextString return the next string follow this keyword sectin.\r
+ @param NextString return the next string follow this keyword section.\r
@param ReadOnly Return whether this question is read only.\r
\r
@retval KEYWORD_HANDLER_NO_ERROR Success validate.\r
@param BufferSize Length of the buffer.\r
@param StringDest Buffer to store the string text. \r
\r
- @retval EFI_SUCCESS The string text was outputed successfully.\r
+ @retval EFI_SUCCESS The string text was outputted successfully.\r
@retval EFI_OUT_OF_RESOURCES Out of resource.\r
\r
**/\r
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
//\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
if (EFI_ERROR (Status)) {\r
goto Done;\r
}\r
- \r
+ ASSERT (String != NULL);\r
if (StrCmp(KeywordValue, String) == 0) {\r
*StringId = CurrentStringId;\r
goto Done;\r
if (EFI_ERROR (Status)) {\r
goto Done;\r
}\r
- \r
+ ASSERT (String != NULL);\r
if (StrCmp(KeywordValue, String) == 0) {\r
*StringId = CurrentStringId;\r
goto Done;\r
if (EFI_ERROR (Status)) {\r
goto Done;\r
}\r
-\r
+ ASSERT (String != NULL);\r
BlockSize += StringSize;\r
if (StrCmp(KeywordValue, String) == 0) {\r
*StringId = CurrentStringId;\r
if (EFI_ERROR (Status)) {\r
goto Done;\r
}\r
-\r
+ ASSERT (String != NULL);\r
BlockSize += StringSize;\r
if (StrCmp(KeywordValue, String) == 0) {\r
*StringId = CurrentStringId;\r
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
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
\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
\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
@param KeywordValue Keyword value.\r
@param StringId String Id for this keyword.\r
\r
- @retval KEYWORD_HANDLER_NO_ERROR Get String id succes.\r
+ @retval KEYWORD_HANDLER_NO_ERROR Get String id successfully.\r
@retval KEYWORD_HANDLER_KEYWORD_NOT_FOUND Not found the string id in the string package.\r
@retval KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND Not found the string package for this namespace.\r
@retval KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR Out of resource error.\r
}\r
\r
/**\r
- Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for \r
+ Converts all hex string characters in range ['A'..'F'] to ['a'..'f'] for\r
hex digits that appear between a '=' and a '&' in a config string.\r
\r
If ConfigString is NULL, then ASSERT().\r
@param[in] DriverHandle The driver handle which supports a Device Path Protocol\r
that is the routing information PATH. Each byte of\r
the Device Path associated with DriverHandle is converted\r
- to a 2 Unicode character hexidecimal string.\r
+ to a 2 Unicode character hexadecimal string.\r
\r
@retval NULL DriverHandle does not support the Device Path Protocol.\r
@retval Other A pointer to the Null-terminate Unicode <ConfigHdr> string\r
UINT8 *Buffer;\r
CHAR16 *Name;\r
CHAR8 *AsciiName;\r
+ UINTN NameSize;\r
EFI_GUID *Guid;\r
UINTN MaxLen;\r
\r
}\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
// Append Guid converted to <HexCh>32\r
//\r
for (Index = 0, Buffer = (UINT8 *)Guid; Index < sizeof (EFI_GUID); Index++) {\r
- String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(Buffer++), 2);\r
+ UnicodeValueToStringS (\r
+ String,\r
+ MaxLen * sizeof (CHAR16) - ((UINTN)String - (UINTN)ReturnString),\r
+ PREFIX_ZERO | RADIX_HEX,\r
+ *(Buffer++),\r
+ 2\r
+ );\r
+ String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16));\r
}\r
}\r
\r
// Append Name converted to <Char>NameLength\r
//\r
for (; *Name != L'\0'; Name++) {\r
- String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *Name, 4);\r
+ UnicodeValueToStringS (\r
+ String,\r
+ MaxLen * sizeof (CHAR16) - ((UINTN)String - (UINTN)ReturnString),\r
+ PREFIX_ZERO | RADIX_HEX,\r
+ *Name,\r
+ 4\r
+ );\r
+ String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16));\r
}\r
}\r
\r
// Append the device path associated with DriverHandle converted to <HexChar>DevicePathSize\r
//\r
for (Index = 0, Buffer = (UINT8 *)DevicePath; Index < DevicePathSize; Index++) {\r
- String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(Buffer++), 2);\r
+ UnicodeValueToStringS (\r
+ String,\r
+ MaxLen * sizeof (CHAR16) - ((UINTN)String - (UINTN)ReturnString),\r
+ PREFIX_ZERO | RADIX_HEX,\r
+ *(Buffer++),\r
+ 2\r
+ );\r
+ String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16));\r
}\r
\r
//\r
}\r
\r
/**\r
- Genereate the KeywordResp String.\r
+ Generate the KeywordResp String.\r
\r
<KeywordResp> ::= <NameSpaceId><PathHdr>'&'<Keyword>'&VALUE='<Number>['&READONLY']\r
\r
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
// 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
RespStrLen += StrLen (PathHdr);\r
\r
//\r
- // 1.3 Keyword setion.\r
+ // 1.3 Keyword section.\r
// 'KEYWORD='<String>[':'<DecCh>(1/4)]\r
//\r
RespStrLen += 8 + StrLen (KeywordData);\r
}\r
\r
//\r
- // return the already get MultiKeywordString even error occured.\r
+ // return the already get MultiKeywordString even error occurred.\r
//\r
if (MultiKeywordResp == NULL) {\r
Status = EFI_NOT_FOUND;\r
StringPtr = NextStringPtr;\r
\r
//\r
- // 5. Find ReadOnly filter.\r
+ // 5. Find READONLY tag.\r
//\r
- if ((StringPtr != NULL) && StrnCmp (StringPtr, L"&ReadOnly", StrLen (L"&ReadOnly")) == 0) {\r
+ if ((StringPtr != NULL) && StrnCmp (StringPtr, L"&READONLY", StrLen (L"&READONLY")) == 0) {\r
ReadOnly = TRUE;\r
- StringPtr += StrLen (L"&ReadOnly");\r
+ StringPtr += StrLen (L"&READONLY");\r
} else {\r
ReadOnly = FALSE;\r
}\r
// 8. Check the readonly flag.\r
//\r
if (ExtractReadOnlyFromOpCode (OpCode) != ReadOnly) {\r
+ //\r
+ // Extracting readonly flag form opcode and extracting "READONLY" tag form KeywordString should have the same results.\r
+ // If not, the input KeywordString must be incorrect, return the error status to caller.\r
+ //\r
+ *ProgressErr = KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED;\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto Done;\r
+ }\r
+ if (ReadOnly) {\r
*ProgressErr = KEYWORD_HANDLER_ACCESS_NOT_PERMITTED;\r
Status = EFI_ACCESS_DENIED;\r
- goto Done; \r
+ goto Done;\r
}\r
\r
//\r
@retval EFI_SUCCESS The specified action was completed successfully.\r
\r
@retval EFI_INVALID_PARAMETER One or more of the following are TRUE:\r
- 1.Progress, ProgressErr, or Resuts is NULL.\r
+ 1.Progress, ProgressErr, or Results is NULL.\r
2.Parsing of the KeywordString resulted in an error. See\r
Progress and ProgressErr for more data.\r
\r