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

Mike Beaton posted 1 patch 7 months, 1 week ago
Failed in applying to current master (apply log)
MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[edk2-devel] [PATCH v5] MdeModulePkg/HiiDatabase: Fix incorrect AllocateCopyPool size
Posted by Mike Beaton 7 months, 1 week ago
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@gmail.com>
---
 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 (#108357): https://edk2.groups.io/g/devel/message/108357
Mute This Topic: https://groups.io/mt/101208544/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v5] MdeModulePkg/HiiDatabase: Fix incorrect AllocateCopyPool size
Posted by Dandan Bi 7 months, 1 week ago
Reviewed-by: Dandan Bi <dandan.bi@intel.com>


Thanks,
Dandan

-----Original Message-----
From: Mike Beaton <mjsbeaton@gmail.com> 
Sent: Thursday, September 7, 2023 11:35 AM
To: devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@intel.com>; Bi, Dandan <dandan.bi@intel.com>; Ard Biesheuvel <ardb@kernel.org>; Mike Beaton <mjsbeaton@gmail.com>
Subject: [PATCH v5] MdeModulePkg/HiiDatabase: Fix incorrect AllocateCopyPool size

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@gmail.com>
---
 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 (#108433): https://edk2.groups.io/g/devel/message/108433
Mute This Topic: https://groups.io/mt/101208544/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
回复: [edk2-devel] [PATCH v5] MdeModulePkg/HiiDatabase: Fix incorrect AllocateCopyPool size
Posted by gaoliming via groups.io 7 months ago
PR https://github.com/tianocore/edk2/pull/4816 is created to merge this
patch. 

Thanks
Liming
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Dandan Bi
> 发送时间: 2023年9月8日 9:22
> 收件人: Mike Beaton <mjsbeaton@gmail.com>; devel@edk2.groups.io
> 抄送: Dong, Eric <eric.dong@intel.com>; Ard Biesheuvel <ardb@kernel.org>
> 主题: Re: [edk2-devel] [PATCH v5] MdeModulePkg/HiiDatabase: Fix incorrect
> AllocateCopyPool size
> 
> Reviewed-by: Dandan Bi <dandan.bi@intel.com>
> 
> 
> Thanks,
> Dandan
> 
> -----Original Message-----
> From: Mike Beaton <mjsbeaton@gmail.com>
> Sent: Thursday, September 7, 2023 11:35 AM
> To: devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@intel.com>; Bi, Dandan <dandan.bi@intel.com>;
> Ard Biesheuvel <ardb@kernel.org>; Mike Beaton <mjsbeaton@gmail.com>
> Subject: [PATCH v5] MdeModulePkg/HiiDatabase: Fix incorrect
> AllocateCopyPool size
> 
> 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@gmail.com>
> ---
>  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 (#108468): https://edk2.groups.io/g/devel/message/108468
Mute This Topic: https://groups.io/mt/101283979/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
回复: [edk2-devel] [PATCH v5] MdeModulePkg/HiiDatabase: Fix incorrect AllocateCopyPool size
Posted by gaoliming via groups.io 7 months, 1 week ago
Mike:
  Thanks for your detail information in the commit message. This change is
very clear. 

  Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>

Thanks
Liming
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Mike Beaton
> 发送时间: 2023年9月7日 11:35
> 收件人: devel@edk2.groups.io
> 抄送: Eric Dong <eric.dong@intel.com>; Dandan Bi <dandan.bi@intel.com>;
> Ard Biesheuvel <ardb@kernel.org>; Mike Beaton <mjsbeaton@gmail.com>
> 主题: [edk2-devel] [PATCH v5] MdeModulePkg/HiiDatabase: Fix incorrect
> AllocateCopyPool size
> 
> 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@gmail.com>
> ---
>  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 (#108430): https://edk2.groups.io/g/devel/message/108430
Mute This Topic: https://groups.io/mt/101228368/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v5] MdeModulePkg/HiiDatabase: Fix incorrect AllocateCopyPool size
Posted by Ard Biesheuvel 7 months, 1 week ago
On Thu, 7 Sept 2023 at 05:35, Mike Beaton <mjsbeaton@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@gmail.com>

Thanks for the fix.

Reviewed-by: Ard Biesheuvel <ardb@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/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH v5] MdeModulePkg/HiiDatabase: Fix incorrect AllocateCopyPool size
Posted by Mike Beaton 7 months, 1 week ago
On Thu, 7 Sept 2023 at 04:35, Mike Beaton <mjsbeaton@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).

Apologies for the multiple versions, but I thought it was important to
clarify in the
commit message above that this really was a fix, not a misunderstanding. I also
realised, in this last version, that sizeof is preferable here to
AsciiStrSize (and
that sizeof is, in fact, already often used when copying static
strings elsewhere
in the codebase - both sizeof and (Ascii)StrSize are used in various places, but
with more use of sizeof).


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108358): https://edk2.groups.io/g/devel/message/108358
Mute This Topic: https://groups.io/mt/101208544/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-