X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FHiiDatabaseDxe%2FConfigKeywordHandler.c;h=8e23a51533d63902d5302d4b39ff7698d81a2c2f;hb=0438f5e287fa40c7aa143c3a151c5e5c743411b3;hp=2f04411683a16b7db8130b90005375dac974506a;hpb=4e295e039202138885281cf4054dd0be4d347691;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c index 2f04411683..8e23a51533 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c @@ -1,7 +1,7 @@ /** @file Implementation of interfaces function for EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL. -Copyright (c) 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -28,7 +28,7 @@ extern HII_DATABASE_PRIVATE_DATA mPrivate; @param NextString string follow the possible PathHdr string. @retval EFI_INVALID_PARAMETER The device path is not valid or the incoming parameter is invalid. - @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures. + @retval EFI_OUT_OF_RESOURCES Lake of resources to store necessary structures. @retval EFI_SUCCESS The device path is retrieved and translated to binary format. The Input string not include PathHdr section. @@ -178,6 +178,7 @@ ExtractNameSpace ( ) { CHAR16 *TmpPtr; + UINTN NameSpaceSize; ASSERT (NameSpace != NULL); @@ -218,11 +219,12 @@ ExtractNameSpace ( // Input NameSpace is unicode string. The language in String package is ascii string. // Here will convert the unicode string to ascii and save it. // - *NameSpace = AllocatePool (StrLen (String) + 1); + NameSpaceSize = StrLen (String) + 1; + *NameSpace = AllocatePool (NameSpaceSize); if (*NameSpace == NULL) { return EFI_OUT_OF_RESOURCES; } - UnicodeStrToAsciiStr (String, *NameSpace); + UnicodeStrToAsciiStrS (String, *NameSpace, NameSpaceSize); if (TmpPtr != NULL) { *TmpPtr = L'&'; @@ -238,10 +240,10 @@ ExtractNameSpace ( @param String KeywordRequestformat string. @param Keyword return the extract keyword string. - @param NextString return the next string follow this keyword sectin. + @param NextString return the next string follow this keyword section. @retval EFI_SUCCESS Success to get the keyword string. - @retval EFI_INVALID_PARAMETER Parsr the input string return error. + @retval EFI_INVALID_PARAMETER Parse the input string return error. **/ EFI_STATUS @@ -304,10 +306,10 @@ ExtractKeyword ( @param String KeywordRequestformat string. @param Value return the extract value string. - @param NextString return the next string follow this keyword sectin. + @param NextString return the next string follow this keyword section. @retval EFI_SUCCESS Success to get the keyword string. - @retval EFI_INVALID_PARAMETER Parsr the input string return error. + @retval EFI_INVALID_PARAMETER Parse the input string return error. **/ EFI_STATUS @@ -359,10 +361,10 @@ ExtractValue ( @param String KeywordRequestformat string. @param FilterFlags return the filter condition. - @param NextString return the next string follow this keyword sectin. + @param NextString return the next string follow this keyword section. @retval EFI_SUCCESS Success to get the keyword string. - @retval EFI_INVALID_PARAMETER Parsr the input string return error. + @retval EFI_INVALID_PARAMETER Parse the input string return error. **/ BOOLEAN @@ -475,7 +477,7 @@ ExtractFilter ( String = KeywordPtr; } else { // - // Only has paltform defined filter section, just skip it. + // Only has platform defined filter section, just skip it. // String += StrLen (String); } @@ -518,9 +520,9 @@ ExtractReadOnlyFromOpCode ( This is a internal function. - @param OpCodeData The questin binary ifr data. + @param OpCodeData The question binary ifr data. @param KeywordRequest KeywordRequestformat string. - @param NextString return the next string follow this keyword sectin. + @param NextString return the next string follow this keyword section. @param ReadOnly Return whether this question is read only. @retval KEYWORD_HANDLER_NO_ERROR Success validate. @@ -709,7 +711,7 @@ GetRecordFromDevicePath ( @param BufferSize Length of the buffer. @param StringDest Buffer to store the string text. - @retval EFI_SUCCESS The string text was outputed successfully. + @retval EFI_SUCCESS The string text was outputted successfully. @retval EFI_OUT_OF_RESOURCES Out of resource. **/ @@ -779,6 +781,7 @@ GetStringIdFromString ( UINTN StringSize; CHAR16 *String; CHAR8 *AsciiKeywordValue; + UINTN KeywordValueSize; EFI_STATUS Status; ASSERT (StringPackage != NULL && KeywordValue != NULL && StringId != NULL); @@ -794,11 +797,12 @@ GetStringIdFromString ( // // Make a ascii keyword value for later use. // - AsciiKeywordValue = AllocatePool (StrLen (KeywordValue) + 1); + KeywordValueSize = StrLen (KeywordValue) + 1; + AsciiKeywordValue = AllocatePool (KeywordValueSize); if (AsciiKeywordValue == NULL) { return EFI_OUT_OF_RESOURCES; } - UnicodeStrToAsciiStr(KeywordValue, AsciiKeywordValue); + UnicodeStrToAsciiStrS (KeywordValue, AsciiKeywordValue, KeywordValueSize); while (*BlockHdr != EFI_HII_SIBT_END) { switch (*BlockHdr) { @@ -871,7 +875,7 @@ GetStringIdFromString ( if (EFI_ERROR (Status)) { goto Done; } - + ASSERT (String != NULL); if (StrCmp(KeywordValue, String) == 0) { *StringId = CurrentStringId; goto Done; @@ -891,7 +895,7 @@ GetStringIdFromString ( if (EFI_ERROR (Status)) { goto Done; } - + ASSERT (String != NULL); if (StrCmp(KeywordValue, String) == 0) { *StringId = CurrentStringId; goto Done; @@ -910,7 +914,7 @@ GetStringIdFromString ( if (EFI_ERROR (Status)) { goto Done; } - + ASSERT (String != NULL); BlockSize += StringSize; if (StrCmp(KeywordValue, String) == 0) { *StringId = CurrentStringId; @@ -935,7 +939,7 @@ GetStringIdFromString ( if (EFI_ERROR (Status)) { goto Done; } - + ASSERT (String != NULL); BlockSize += StringSize; if (StrCmp(KeywordValue, String) == 0) { *StringId = CurrentStringId; @@ -1065,11 +1069,12 @@ GetNextStringId ( StringTextPtr = BlockHdr + Offset; if (FindString) { - *KeywordValue = AllocatePool (AsciiStrSize ((CHAR8 *) StringTextPtr) * sizeof (CHAR16)); + StringSize = AsciiStrSize ((CHAR8 *) StringTextPtr); + *KeywordValue = AllocatePool (StringSize * sizeof (CHAR16)); if (*KeywordValue == NULL) { return 0; } - AsciiStrToUnicodeStr ((CHAR8 *) StringTextPtr, *KeywordValue); + AsciiStrToUnicodeStrS ((CHAR8 *) StringTextPtr, *KeywordValue, StringSize); return CurrentStringId; } else if (CurrentStringId == StringId) { FindString = TRUE; @@ -1084,11 +1089,12 @@ GetNextStringId ( StringTextPtr = BlockHdr + Offset; if (FindString) { - *KeywordValue = AllocatePool (AsciiStrSize ((CHAR8 *) StringTextPtr) * sizeof (CHAR16)); + StringSize = AsciiStrSize ((CHAR8 *) StringTextPtr); + *KeywordValue = AllocatePool (StringSize * sizeof (CHAR16)); if (*KeywordValue == NULL) { return 0; } - AsciiStrToUnicodeStr ((CHAR8 *) StringTextPtr, *KeywordValue); + AsciiStrToUnicodeStrS ((CHAR8 *) StringTextPtr, *KeywordValue, StringSize); return CurrentStringId; } else if (CurrentStringId == StringId) { FindString = TRUE; @@ -1105,11 +1111,12 @@ GetNextStringId ( for (Index = 0; Index < StringCount; Index++) { if (FindString) { - *KeywordValue = AllocatePool (AsciiStrSize ((CHAR8 *) StringTextPtr) * sizeof (CHAR16)); + StringSize = AsciiStrSize ((CHAR8 *) StringTextPtr); + *KeywordValue = AllocatePool (StringSize * sizeof (CHAR16)); if (*KeywordValue == NULL) { return 0; } - AsciiStrToUnicodeStr ((CHAR8 *) StringTextPtr, *KeywordValue); + AsciiStrToUnicodeStrS ((CHAR8 *) StringTextPtr, *KeywordValue, StringSize); return CurrentStringId; } else if (CurrentStringId == StringId) { FindString = TRUE; @@ -1132,11 +1139,12 @@ GetNextStringId ( for (Index = 0; Index < StringCount; Index++) { if (FindString) { - *KeywordValue = AllocatePool (AsciiStrSize ((CHAR8 *) StringTextPtr) * sizeof (CHAR16)); + StringSize = AsciiStrSize ((CHAR8 *) StringTextPtr); + *KeywordValue = AllocatePool (StringSize * sizeof (CHAR16)); if (*KeywordValue == NULL) { return 0; } - AsciiStrToUnicodeStr ((CHAR8 *) StringTextPtr, *KeywordValue); + AsciiStrToUnicodeStrS ((CHAR8 *) StringTextPtr, *KeywordValue, StringSize); return CurrentStringId; } else if (CurrentStringId == StringId) { FindString = TRUE; @@ -1302,7 +1310,7 @@ GetNextStringId ( @param KeywordValue Keyword value. @param StringId String Id for this keyword. - @retval KEYWORD_HANDLER_NO_ERROR Get String id succes. + @retval KEYWORD_HANDLER_NO_ERROR Get String id successfully. @retval KEYWORD_HANDLER_KEYWORD_NOT_FOUND Not found the string id in the string package. @retval KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND Not found the string package for this namespace. @retval KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR Out of resource error. @@ -1340,8 +1348,7 @@ GetStringIdFromRecord ( if (AsciiStrnCmp(Name, StringPackage->StringPkgHdr->Language, AsciiStrLen (Name)) == 0) { Status = GetStringIdFromString (StringPackage, KeywordValue, StringId); if (EFI_ERROR (Status)) { - RetVal = KEYWORD_HANDLER_KEYWORD_NOT_FOUND; - continue; + return KEYWORD_HANDLER_KEYWORD_NOT_FOUND; } else { if (*NameSpace == NULL) { *NameSpace = AllocateCopyPool (AsciiStrSize (StringPackage->StringPkgHdr->Language), StringPackage->StringPkgHdr->Language); @@ -1584,6 +1591,8 @@ GetWidth ( return (UINT16) sizeof (BOOLEAN); case EFI_IFR_PASSWORD_OP: + return (UINT16)((UINTN) ((EFI_IFR_PASSWORD *) OpCodeData)->MaxSize * sizeof (CHAR16)); + case EFI_IFR_STRING_OP: return (UINT16)((UINTN) ((EFI_IFR_STRING *) OpCodeData)->MaxSize * sizeof (CHAR16)); @@ -1600,7 +1609,7 @@ GetWidth ( } /** - Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for + Converts all hex string characters in range ['A'..'F'] to ['a'..'f'] for hex digits that appear between a '=' and a '&' in a config string. If ConfigString is NULL, then ASSERT(). @@ -1648,7 +1657,7 @@ InternalLowerConfigString ( @param[in] DriverHandle The driver handle which supports a Device Path Protocol that is the routing information PATH. Each byte of the Device Path associated with DriverHandle is converted - to a 2 Unicode character hexidecimal string. + to a 2 Unicode character hexadecimal string. @retval NULL DriverHandle does not support the Device Path Protocol. @retval Other A pointer to the Null-terminate Unicode string @@ -1669,7 +1678,9 @@ ConstructConfigHdr ( UINT8 *Buffer; CHAR16 *Name; CHAR8 *AsciiName; + UINTN NameSize; EFI_GUID *Guid; + UINTN MaxLen; ASSERT (OpCodeData != NULL); @@ -1697,9 +1708,10 @@ ConstructConfigHdr ( } if (AsciiName != NULL) { - Name = AllocateZeroPool (AsciiStrSize (AsciiName) * 2); + NameSize = AsciiStrSize (AsciiName); + Name = AllocateZeroPool (NameSize * sizeof (CHAR16)); ASSERT (Name != NULL); - AsciiStrToUnicodeStr(AsciiName, Name); + AsciiStrToUnicodeStrS (AsciiName, Name, NameSize); } else { Name = NULL; } @@ -1733,7 +1745,8 @@ ConstructConfigHdr ( // GUID=32&NAME=NameLength&PATH=DevicePathSize // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 | // - String = AllocateZeroPool ((5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathSize * 2 + 1) * sizeof (CHAR16)); + MaxLen = 5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathSize * 2 + 1; + String = AllocateZeroPool (MaxLen * sizeof (CHAR16)); if (String == NULL) { return NULL; } @@ -1741,7 +1754,8 @@ ConstructConfigHdr ( // // Start with L"GUID=" // - ReturnString = StrCpy (String, L"GUID="); + StrCpyS (String, MaxLen, L"GUID="); + ReturnString = String; String += StrLen (String); if (Guid != NULL) { @@ -1756,7 +1770,7 @@ ConstructConfigHdr ( // // Append L"&NAME=" // - StrCpy (String, L"&NAME="); + StrCatS (ReturnString, MaxLen, L"&NAME="); String += StrLen (String); if (Name != NULL) { @@ -1771,7 +1785,7 @@ ConstructConfigHdr ( // // Append L"&PATH=" // - StrCpy (String, L"&PATH="); + StrCatS (ReturnString, MaxLen, L"&PATH="); String += StrLen (String); // @@ -1991,7 +2005,7 @@ ExtractConfigRequest ( UINT16 Width; CHAR16 *ConfigHdr; CHAR16 *RequestElement; - UINTN Length; + UINTN MaxLen; CHAR16 *StringPtr; ASSERT (DatabaseRecord != NULL && OpCodeData != NULL && ConfigRequest != NULL); @@ -2032,8 +2046,8 @@ ExtractConfigRequest ( ConfigHdr = ConstructConfigHdr(Storage, DatabaseRecord->DriverHandle); ASSERT (ConfigHdr != NULL); - Length = (StrLen (ConfigHdr) + 1 + StrLen(RequestElement) + 1) * sizeof (CHAR16); - *ConfigRequest = AllocatePool (Length); + MaxLen = StrLen (ConfigHdr) + 1 + StrLen(RequestElement) + 1; + *ConfigRequest = AllocatePool (MaxLen * sizeof (CHAR16)); if (*ConfigRequest == NULL) { FreePool (ConfigHdr); FreePool (RequestElement); @@ -2041,15 +2055,11 @@ ExtractConfigRequest ( } StringPtr = *ConfigRequest; - StrCpy (StringPtr, ConfigHdr); - StringPtr += StrLen (StringPtr); + StrCpyS (StringPtr, MaxLen, ConfigHdr); - *StringPtr = L'&'; - StringPtr++; + StrCatS (StringPtr, MaxLen, L"&"); - StrCpy (StringPtr, RequestElement); - StringPtr += StrLen (StringPtr); - *StringPtr = L'\0'; + StrCatS (StringPtr, MaxLen, RequestElement); FreePool (ConfigHdr); FreePool (RequestElement); @@ -2098,7 +2108,7 @@ ExtractConfigResp ( UINT16 Width; CHAR16 *ConfigHdr; CHAR16 *RequestElement; - UINTN Length; + UINTN MaxLen; CHAR16 *StringPtr; ASSERT ((DatabaseRecord != NULL) && (OpCodeData != NULL) && (ConfigResp != NULL) && (ValueElement != NULL)); @@ -2140,8 +2150,8 @@ ExtractConfigResp ( ConfigHdr = ConstructConfigHdr(Storage, DatabaseRecord->DriverHandle); ASSERT (ConfigHdr != NULL); - Length = (StrLen (ConfigHdr) + 1 + StrLen(RequestElement) + 1 + StrLen (L"VALUE=") + StrLen(ValueElement) + 1) * sizeof (CHAR16); - *ConfigResp = AllocatePool (Length); + MaxLen = StrLen (ConfigHdr) + 1 + StrLen(RequestElement) + 1 + StrLen (L"VALUE=") + StrLen(ValueElement) + 1; + *ConfigResp = AllocatePool (MaxLen * sizeof (CHAR16)); if (*ConfigResp == NULL) { FreePool (ConfigHdr); FreePool (RequestElement); @@ -2149,24 +2159,18 @@ ExtractConfigResp ( } StringPtr = *ConfigResp; - StrCpy (StringPtr, ConfigHdr); - StringPtr += StrLen (StringPtr); + StrCpyS (StringPtr, MaxLen, ConfigHdr); - *StringPtr = L'&'; - StringPtr++; + StrCatS (StringPtr, MaxLen, L"&"); - StrCpy (StringPtr, RequestElement); - StringPtr += StrLen (StringPtr); - - *StringPtr = L'&'; - StringPtr++; - StrCpy (StringPtr, L"VALUE="); - StringPtr += StrLen (StringPtr); + StrCatS (StringPtr, MaxLen, RequestElement); + + StrCatS (StringPtr, MaxLen, L"&"); - StrCpy (StringPtr, ValueElement); - StringPtr += StrLen (StringPtr); - *StringPtr = L'\0'; + StrCatS (StringPtr, MaxLen, L"VALUE="); + + StrCatS (StringPtr, MaxLen, ValueElement); FreePool (ConfigHdr); FreePool (RequestElement); @@ -2352,7 +2356,7 @@ GetStringIdFromDatabase ( } /** - Genereate the KeywordResp String. + Generate the KeywordResp String. ::= '&''&VALUE='['&READONLY'] @@ -2381,6 +2385,7 @@ GenerateKeywordResp ( CHAR16 *RespStr; CHAR16 *PathHdr; CHAR16 *UnicodeNameSpace; + UINTN NameSpaceLength; ASSERT ((NameSpace != NULL) && (DevicePath != NULL) && (KeywordData != NULL) && (ValueStr != NULL) && (KeywordResp != NULL)); @@ -2391,12 +2396,13 @@ GenerateKeywordResp ( // 1.1 NameSpaceId size. // 'NAMESPACE=' // - RespStrLen = 10 + AsciiStrLen (NameSpace); - UnicodeNameSpace = AllocatePool ((AsciiStrLen (NameSpace) + 1) * sizeof (CHAR16)); + NameSpaceLength = AsciiStrLen (NameSpace); + RespStrLen = 10 + NameSpaceLength; + UnicodeNameSpace = AllocatePool ((NameSpaceLength + 1) * sizeof (CHAR16)); if (UnicodeNameSpace == NULL) { return EFI_OUT_OF_RESOURCES; } - AsciiStrToUnicodeStr(NameSpace, UnicodeNameSpace); + AsciiStrToUnicodeStrS (NameSpace, UnicodeNameSpace, NameSpaceLength + 1); // // 1.2 PathHdr size. @@ -2413,7 +2419,7 @@ GenerateKeywordResp ( RespStrLen += StrLen (PathHdr); // - // 1.3 Keyword setion. + // 1.3 Keyword section. // 'KEYWORD='[':'(1/4)] // RespStrLen += 8 + StrLen (KeywordData); @@ -2433,9 +2439,10 @@ GenerateKeywordResp ( } // - // 2. Allocate the buffer and create the KeywordResp string. + // 2. Allocate the buffer and create the KeywordResp string include '\0'. // - *KeywordResp = AllocatePool ((RespStrLen + 1) * sizeof (CHAR16)); + RespStrLen += 1; + *KeywordResp = AllocatePool (RespStrLen * sizeof (CHAR16)); if (*KeywordResp == NULL) { if (UnicodeNameSpace != NULL) { FreePool (UnicodeNameSpace); @@ -2448,44 +2455,34 @@ GenerateKeywordResp ( // // 2.1 Copy NameSpaceId section. // - StrCpy (RespStr, L"NAMESPACE="); - RespStr += StrLen (RespStr); - StrCpy (RespStr, UnicodeNameSpace); - RespStr += StrLen (RespStr); + StrCpyS (RespStr, RespStrLen, L"NAMESPACE="); + + StrCatS (RespStr, RespStrLen, UnicodeNameSpace); // // 2.2 Copy PathHdr section. // - StrCpy (RespStr, PathHdr); - RespStr += StrLen (RespStr); + StrCatS (RespStr, RespStrLen, PathHdr); // // 2.3 Copy Keyword section. // - StrCpy (RespStr, L"KEYWORD="); - RespStr += StrLen (RespStr); - StrCpy (RespStr, KeywordData); - RespStr += StrLen (RespStr); + StrCatS (RespStr, RespStrLen, L"KEYWORD="); + + StrCatS (RespStr, RespStrLen, KeywordData); // // 2.4 Copy the Value section. // - StrCpy (RespStr, ValueStr); - RespStr += StrLen (RespStr); + StrCatS (RespStr, RespStrLen, ValueStr); // // 2.5 Copy ReadOnly section if exist. // if (ReadOnly) { - StrCpy (RespStr, L"&READONLY"); - RespStr += StrLen (RespStr); + StrCatS (RespStr, RespStrLen, L"&READONLY"); } - // - // 2.6 Add the end. - // - *RespStr = L'\0'; - if (UnicodeNameSpace != NULL) { FreePool (UnicodeNameSpace); } @@ -2533,12 +2530,9 @@ MergeToMultiKeywordResp ( FreePool (*MultiKeywordResp); *MultiKeywordResp = StringPtr; - StringPtr += StrLen (StringPtr); - - *StringPtr = L'&'; - StringPtr++; + StrCatS (StringPtr, MultiKeywordRespLen / sizeof (CHAR16), L"&"); - StrCpy (StringPtr, *KeywordResp); + StrCatS (StringPtr, MultiKeywordRespLen / sizeof (CHAR16), *KeywordResp); return EFI_SUCCESS; } @@ -2552,6 +2546,7 @@ MergeToMultiKeywordResp ( @param NameSpace The namespace used to search the string. @param MultiResp Return the MultiKeywordResp string for the system. + @param ProgressErr Return the error status. @retval EFI_OUT_OF_RESOURCES The memory can't be allocated. @retval EFI_SUCCESS Generate the MultiKeywordResp string. @@ -2561,7 +2556,8 @@ MergeToMultiKeywordResp ( EFI_STATUS EnumerateAllKeywords ( IN CHAR8 *NameSpace, - OUT EFI_STRING *MultiResp + OUT EFI_STRING *MultiResp, + OUT UINT32 *ProgressErr ) { LIST_ENTRY *Link; @@ -2581,6 +2577,7 @@ EnumerateAllKeywords ( CHAR16 *MultiKeywordResp; CHAR16 *KeywordData; BOOLEAN ReadOnly; + BOOLEAN FindKeywordPackages; DataBaseRecord = NULL; Status = EFI_SUCCESS; @@ -2590,6 +2587,7 @@ EnumerateAllKeywords ( ConfigRequest = NULL; ValueElement = NULL; KeywordResp = NULL; + FindKeywordPackages = FALSE; if (NameSpace == NULL) { NameSpace = UEFI_CONFIG_LANG; @@ -2612,6 +2610,7 @@ EnumerateAllKeywords ( // Check whether has keyword string package. // if (AsciiStrnCmp(NameSpace, StringPackage->StringPkgHdr->Language, AsciiStrLen (NameSpace)) == 0) { + FindKeywordPackages = TRUE; // // Keep the NameSpace string. // @@ -2710,10 +2709,15 @@ Error: } // - // return the already get MultiKeywordString even error occured. + // return the already get MultiKeywordString even error occurred. // if (MultiKeywordResp == NULL) { Status = EFI_NOT_FOUND; + if (!FindKeywordPackages) { + *ProgressErr = KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND; + } else { + *ProgressErr = KEYWORD_HANDLER_KEYWORD_NOT_FOUND; + } } else { Status = EFI_SUCCESS; } @@ -2762,8 +2766,9 @@ Done: @param Progress On return, points to a character in the KeywordString. Points to the string's NULL terminator if the request was successful. Points to the most recent '&' before - the first failing string element if the request was - not successful. + the first failing name / value pair (or the beginning + of the string if the failure is in the first name / value + pair) if the request was not successful. @param ProgressErr If during the processing of the KeywordString there was a failure, this parameter gives additional information @@ -2804,7 +2809,7 @@ EfiConfigKeywordHandlerSetData ( EFI_STATUS Status; CHAR16 *StringPtr; EFI_DEVICE_PATH_PROTOCOL *DevicePath; - CHAR16 *NextStringPtr; + CHAR16 *NextStringPtr; CHAR16 *KeywordData; EFI_STRING_ID KeywordStringId; UINT32 RetVal; @@ -2815,6 +2820,8 @@ EfiConfigKeywordHandlerSetData ( CHAR16 *ValueElement; BOOLEAN ReadOnly; EFI_STRING InternalProgress; + CHAR16 *TempString; + CHAR16 *KeywordStartPos; if (This == NULL || Progress == NULL || ProgressErr == NULL || KeywordString == NULL) { return EFI_INVALID_PARAMETER; @@ -2823,15 +2830,22 @@ EfiConfigKeywordHandlerSetData ( *Progress = KeywordString; *ProgressErr = KEYWORD_HANDLER_UNDEFINED_PROCESSING_ERROR; Status = EFI_SUCCESS; - StringPtr = KeywordString; MultiConfigResp = NULL; NameSpace = NULL; DevicePath = NULL; KeywordData = NULL; ValueElement = NULL; ConfigResp = NULL; + KeywordStartPos = NULL; KeywordStringId = 0; + // + // Use temp string to avoid changing input string buffer. + // + TempString = AllocateCopyPool (StrSize (KeywordString), KeywordString); + ASSERT (TempString != NULL); + StringPtr = TempString; + while ((StringPtr != NULL) && (*StringPtr != L'\0')) { // // 1. Get NameSpace from NameSpaceId keyword. @@ -2839,8 +2853,18 @@ EfiConfigKeywordHandlerSetData ( Status = ExtractNameSpace (StringPtr, &NameSpace, &NextStringPtr); if (EFI_ERROR (Status)) { *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING; - return Status; + goto Done; + } + ASSERT (NameSpace != NULL); + // + // 1.1 Check whether the input namespace is valid. + // + if (AsciiStrnCmp(NameSpace, UEFI_CONFIG_LANG, AsciiStrLen (UEFI_CONFIG_LANG)) != 0) { + *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING; + Status = EFI_INVALID_PARAMETER; + goto Done; } + StringPtr = NextStringPtr; // @@ -2856,6 +2880,7 @@ EfiConfigKeywordHandlerSetData ( // // 3. Extract keyword from the KeywordRequest string. // + KeywordStartPos = StringPtr; Status = ExtractKeyword(StringPtr, &KeywordData, &NextStringPtr); if (EFI_ERROR (Status)) { // @@ -2882,11 +2907,11 @@ EfiConfigKeywordHandlerSetData ( StringPtr = NextStringPtr; // - // 5. Find ReadOnly filter. + // 5. Find READONLY tag. // - if ((StringPtr != NULL) && StrnCmp (StringPtr, L"&ReadOnly", StrLen (L"&ReadOnly")) == 0) { + if ((StringPtr != NULL) && StrnCmp (StringPtr, L"&READONLY", StrLen (L"&READONLY")) == 0) { ReadOnly = TRUE; - StringPtr += StrLen (L"&ReadOnly"); + StringPtr += StrLen (L"&READONLY"); } else { ReadOnly = FALSE; } @@ -2912,9 +2937,18 @@ EfiConfigKeywordHandlerSetData ( // 8. Check the readonly flag. // if (ExtractReadOnlyFromOpCode (OpCode) != ReadOnly) { + // + // Extracting readonly flag form opcode and extracting "READONLY" tag form KeywordString should have the same results. + // If not, the input KeywordString must be incorrect, return the error status to caller. + // *ProgressErr = KEYWORD_HANDLER_INCOMPATIBLE_VALUE_DETECTED; Status = EFI_INVALID_PARAMETER; - goto Done; + goto Done; + } + if (ReadOnly) { + *ProgressErr = KEYWORD_HANDLER_ACCESS_NOT_PERMITTED; + Status = EFI_ACCESS_DENIED; + goto Done; } // @@ -2940,6 +2974,7 @@ EfiConfigKeywordHandlerSetData ( FreePool (ConfigResp); ConfigResp = NULL; } + KeywordStartPos = NULL; } // @@ -2958,6 +2993,14 @@ EfiConfigKeywordHandlerSetData ( *ProgressErr = KEYWORD_HANDLER_NO_ERROR; Done: + if (KeywordStartPos != NULL) { + *Progress = KeywordString + (KeywordStartPos - TempString); + } else { + *Progress = KeywordString + (StringPtr - TempString); + } + + ASSERT (TempString != NULL); + FreePool (TempString); if (NameSpace != NULL) { FreePool (NameSpace); } @@ -2975,8 +3018,8 @@ Done: } if (MultiConfigResp != NULL && MultiConfigResp != ConfigResp) { FreePool (MultiConfigResp); - } - *Progress = StringPtr; + } + return Status; } @@ -3011,8 +3054,9 @@ Done: @param Progress On return, points to a character in the KeywordString. Points to the string's NULL terminator if the request was successful. - Points to the most recent '&' before the first failing string - element if the request was not successful. + Points to the most recent '&' before the first failing name / value + pair (or the beginning of the string if the failure is in the first + name / value pair) if the request was not successful. @param ProgressErr If during the processing of the KeywordString there was a failure, this parameter gives additional information about the @@ -3027,7 +3071,7 @@ Done: @retval EFI_SUCCESS The specified action was completed successfully. @retval EFI_INVALID_PARAMETER One or more of the following are TRUE: - 1.Progress, ProgressErr, or Resuts is NULL. + 1.Progress, ProgressErr, or Results is NULL. 2.Parsing of the KeywordString resulted in an error. See Progress and ProgressErr for more data. @@ -3074,6 +3118,7 @@ EfiConfigKeywordHandlerGetData ( BOOLEAN ReadOnly; CHAR16 *KeywordResp; CHAR16 *MultiKeywordResp; + CHAR16 *TempString; if (This == NULL || Progress == NULL || ProgressErr == NULL || Results == NULL) { return EFI_INVALID_PARAMETER; @@ -3089,18 +3134,44 @@ EfiConfigKeywordHandlerGetData ( ReadOnly = FALSE; MultiKeywordResp = NULL; KeywordStringId = 0; + TempString = NULL; + // + // Use temp string to avoid changing input string buffer. + // + if (NameSpaceId != NULL) { + TempString = AllocateCopyPool (StrSize (NameSpaceId), NameSpaceId); + ASSERT (TempString != NULL); + } // // 1. Get NameSpace from NameSpaceId keyword. // - Status = ExtractNameSpace (NameSpaceId, &NameSpace, NULL); + Status = ExtractNameSpace (TempString, &NameSpace, NULL); + if (TempString != NULL) { + FreePool (TempString); + TempString = NULL; + } if (EFI_ERROR (Status)) { - *ProgressErr = KEYWORD_HANDLER_NAMESPACE_ID_NOT_FOUND; + *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING; return Status; } - + // + // 1.1 Check whether the input namespace is valid. + // + if (NameSpace != NULL){ + if (AsciiStrnCmp(NameSpace, UEFI_CONFIG_LANG, AsciiStrLen (UEFI_CONFIG_LANG)) != 0) { + *ProgressErr = KEYWORD_HANDLER_MALFORMED_STRING; + return EFI_INVALID_PARAMETER; + } + } + if (KeywordString != NULL) { - StringPtr = KeywordString; + // + // Use temp string to avoid changing input string buffer. + // + TempString = AllocateCopyPool (StrSize (KeywordString), KeywordString); + ASSERT (TempString != NULL); + StringPtr = TempString; while (*StringPtr != L'\0') { // @@ -3211,7 +3282,7 @@ EfiConfigKeywordHandlerGetData ( // // Enumerate all keyword in the system. // - Status = EnumerateAllKeywords(NameSpace, &MultiKeywordResp); + Status = EnumerateAllKeywords(NameSpace, &MultiKeywordResp, ProgressErr); if (EFI_ERROR (Status)) { goto Done; } @@ -3221,6 +3292,11 @@ EfiConfigKeywordHandlerGetData ( *ProgressErr = KEYWORD_HANDLER_NO_ERROR; Done: + *Progress = KeywordString + (StringPtr - TempString); + + if (TempString != NULL) { + FreePool (TempString); + } if (NameSpace != NULL) { FreePool (NameSpace); } @@ -3230,6 +3306,6 @@ Done: if (KeywordData != NULL) { FreePool (KeywordData); } - *Progress = StringPtr; + return Status; }