[edk2-devel] [PATCH v5] MdeModulePkg/HiiDatabase: Fix incorrect AllocateCopyPool size

Ard Biesheuvel ardb at kernel.org
Thu Sep 7 10:33:37 UTC 2023


On Thu, 7 Sept 2023 at 05:35, Mike Beaton <mjsbeaton at gmail.com> wrote:
>
> The immediately preceding call, GetBestLanguage, plus the implementation of
> HiiGetString, which is called immediately afterwards, make it clear that
> BestLanguage is a null-terminated ASCII string, and not just a five byte,
> non-null terminated buffer.
>
> Therefore AsciiStrLen is one byte too short, meaning that whether the space
> allocated is really sufficient and whether the resultant string is really
> null-terminated becomes implementation-dependent. Rather than switching to
> AsciiStrSize, we use an explicitly compile-time string length calculation
> (both compile-time and run-time approaches are currently used elsewhere in
> the codebase for copying static strings).
>
> Signed-off-by: Mike Beaton <mjsbeaton at gmail.com>

Thanks for the fix.

Reviewed-by: Ard Biesheuvel <ardb at kernel.org>

> ---
>  MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c
> index 96e05d4cf9..6e791783a6 100644
> --- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c
> +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c
> @@ -1987,7 +1987,7 @@ GetNameFromId (
>                     NULL
>                     );
>    if (BestLanguage == NULL) {
> -    BestLanguage = AllocateCopyPool (AsciiStrLen ("en-US"), "en-US");
> +    BestLanguage = AllocateCopyPool (sizeof ("en-US"), "en-US");
>      ASSERT (BestLanguage != NULL);
>    }
>
> --
> 2.41.0
>
>
>
> 
>
>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108373): https://edk2.groups.io/g/devel/message/108373
Mute This Topic: https://groups.io/mt/101208544/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list