X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FHiiDatabaseDxe%2FString.c;h=a76e5b64c93199f3144ac0615f6a54da5220df0d;hb=7c9fbd79d1fc8b817acb72c61cc19605d2f24907;hp=0846abfe4253c0ed2adbbf565eb4aa6b0b564b9a;hpb=40a699562a69289274441d9a0e97bf40dd92f49e;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/String.c b/MdeModulePkg/Universal/HiiDatabaseDxe/String.c index 0846abfe42..a76e5b64c9 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/String.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/String.c @@ -341,6 +341,7 @@ FindStringBlock ( for (Index = 0; Index < StringCount; Index++) { BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr); if (CurrentStringId == StringId) { + ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL); *BlockType = *BlockHdr; *StringBlockAddr = BlockHdr; *StringTextOffset = StringTextPtr - BlockHdr; @@ -363,6 +364,7 @@ FindStringBlock ( for (Index = 0; Index < StringCount; Index++) { BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr); if (CurrentStringId == StringId) { + ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL); *BlockType = *BlockHdr; *StringBlockAddr = BlockHdr; *StringTextOffset = StringTextPtr - BlockHdr; @@ -406,6 +408,7 @@ FindStringBlock ( GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize); BlockSize += StringSize; if (CurrentStringId == StringId) { + ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL); *BlockType = *BlockHdr; *StringBlockAddr = BlockHdr; *StringTextOffset = StringTextPtr - BlockHdr; @@ -429,6 +432,7 @@ FindStringBlock ( GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize); BlockSize += StringSize; if (CurrentStringId == StringId) { + ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL); *BlockType = *BlockHdr; *StringBlockAddr = BlockHdr; *StringTextOffset = StringTextPtr - BlockHdr; @@ -572,7 +576,7 @@ FindStringBlock ( // // Get last string ID // - if (StringId == (EFI_STRING_ID) (-1)) { + if (StringId == (EFI_STRING_ID) (-1) && LastStringId != NULL) { *LastStringId = (EFI_STRING_ID) (CurrentStringId - 1); return EFI_SUCCESS; } @@ -1763,7 +1767,8 @@ HiiSetString ( @param This A pointer to the EFI_HII_STRING_PROTOCOL instance. @param PackageList The package list to examine. - @param Languages Points to the buffer to hold the returned string. + @param Languages Points to the buffer to hold the returned + null-terminated ASCII string. @param LanguagesSize On entry, points to the size of the buffer pointed to by Languages, in bytes. On return, points to the length of Languages, in bytes. @@ -1851,25 +1856,28 @@ HiiGetLanguages ( @param This A pointer to the EFI_HII_STRING_PROTOCOL instance. @param PackageList The package list to examine. - @param FirstLanguage Points to the primary language. - @param SecondaryLanguages Points to the buffer to hold the returned list of + @param PrimaryLanguage Points to the null-terminated ASCII string that specifies + the primary language. Languages are specified in the + format specified in Appendix M of the UEFI 2.0 specification. + @param SecondaryLanguages Points to the buffer to hold the returned null-terminated + ASCII string that describes the list of secondary languages for the specified - FirstLanguage. If there are no secondary - languages, the function returns successfully, but + PrimaryLanguage. If there are no secondary + languages, the function returns successfully, but this is set to NULL. @param SecondaryLanguagesSize On entry, points to the size of the buffer pointed - to by SecondaryLanguages, in bytes. On return, + to by SecondaryLanguages, in bytes. On return, points to the length of SecondaryLanguages in bytes. @retval EFI_SUCCESS Secondary languages were correctly returned. - @retval EFI_INVALID_PARAMETER FirstLanguage or SecondaryLanguages or + @retval EFI_INVALID_PARAMETER PrimaryLanguage or SecondaryLanguages or SecondaryLanguagesSize was NULL. @retval EFI_BUFFER_TOO_SMALL The buffer specified by SecondaryLanguagesSize is too small to hold the returned information. - SecondLanguageSize is updated to hold the size of + SecondaryLanguageSize is updated to hold the size of the buffer required. - @retval EFI_INVALID_LANGUAGE The language specified by FirstLanguage is not - present in the specified package list. + @retval EFI_INVALID_LANGUAGE The language specified by PrimaryLanguage is not + present in the specified package list. @retval EFI_NOT_FOUND The specified PackageList is not in the Database. **/ @@ -1878,7 +1886,7 @@ EFIAPI HiiGetSecondaryLanguages ( IN CONST EFI_HII_STRING_PROTOCOL *This, IN EFI_HII_HANDLE PackageList, - IN CONST CHAR8 *FirstLanguage, + IN CONST CHAR8 *PrimaryLanguage, IN OUT CHAR8 *SecondaryLanguages, IN OUT UINTN *SecondaryLanguagesSize ) @@ -1892,7 +1900,7 @@ HiiGetSecondaryLanguages ( CHAR8 *Languages; UINTN ResultSize; - if (This == NULL || PackageList == NULL || FirstLanguage == NULL) { + if (This == NULL || PackageList == NULL || PrimaryLanguage == NULL) { return EFI_INVALID_PARAMETER; } if (SecondaryLanguages == NULL || SecondaryLanguagesSize == NULL) { @@ -1923,7 +1931,7 @@ HiiGetSecondaryLanguages ( Link1 = Link1->ForwardLink ) { StringPackage = CR (Link1, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE); - if (HiiCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) FirstLanguage)) { + if (HiiCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) PrimaryLanguage)) { Languages = StringPackage->StringPkgHdr->Language; // // Language is a series of ';' terminated strings, first one is primary @@ -1951,11 +1959,36 @@ HiiGetSecondaryLanguages ( return EFI_INVALID_LANGUAGE; } +/** + Converts the ascii character of the string from uppercase to lowercase. + This is a internal function. + + @param ConfigString String to be converted + +**/ +VOID +EFIAPI +AsciiHiiToLower ( + IN CHAR8 *ConfigString + ) +{ + ASSERT (ConfigString != NULL); + + // + // Convert all hex digits in range [A-F] in the configuration header to [a-f] + // + for (; *ConfigString != '\0'; ConfigString++) { + if ( *ConfigString >= 'A' && *ConfigString <= 'Z') { + *ConfigString = (CHAR8) (*ConfigString - 'A' + 'a'); + } + } +} + /** Compare whether two names of languages are identical. - @param Language1 Name of language 1 - @param Language2 Name of language 2 + @param Language1 Name of language 1 from StringPackage + @param Language2 Name of language 2 to be compared with language 1. @retval TRUE same @retval FALSE not same @@ -1967,25 +2000,48 @@ HiiCompareLanguage ( IN CHAR8 *Language2 ) { + UINTN Index; + UINTN StrLen; + CHAR8 *Lan1; + CHAR8 *Lan2; + // - // Porting Guide: - // This library interface is simply obsolete. - // Include the source code to user code. + // Convert to lower to compare. // - UINTN Index; + StrLen = AsciiStrSize (Language1); + Lan1 = AllocateZeroPool (StrLen); + ASSERT (Lan1 != NULL); + AsciiStrCpy(Lan1, Language1); + AsciiHiiToLower (Lan1); + + StrLen = AsciiStrSize (Language2); + Lan2 = AllocateZeroPool (StrLen); + ASSERT (Lan2 != NULL); + AsciiStrCpy(Lan2, Language2); + AsciiHiiToLower (Lan2); - for (Index = 0; (Language1[Index] != 0) && (Language2[Index] != 0); Index++) { - if (Language1[Index] != Language2[Index]) { + // + // Compare the Primary Language in Language1 to Language2 + // + for (Index = 0; Lan1[Index] != 0 && Lan1[Index] != ';'; Index++) { + if (Lan1[Index] != Lan2[Index]) { + // + // Return FALSE if any characters are different. + // + FreePool (Lan1); + FreePool (Lan2); return FALSE; } } - if (((Language1[Index] == 0) && (Language2[Index] == 0)) || - ((Language1[Index] == 0) && (Language2[Index] != ';')) || - ((Language1[Index] == ';') && (Language2[Index] != 0)) || - ((Language1[Index] == ';') && (Language2[Index] != ';'))) { - return TRUE; - } + FreePool (Lan1); + FreePool (Lan2); - return FALSE; + // + // Only return TRUE if Language2[Index] is a Null-terminator which means + // the Primary Language in Language1 is the same length as Language2. If + // Language2[Index] is not a Null-terminator, then Language2 is longer than + // the Primary Language in Language1, and FALSE must be returned. + // + return (BOOLEAN) (Language2[Index] == 0); }