[edk2] [patch] MdeModulePkg/HiiDatabase: clean the value before setting default string

Dandan Bi posted 1 patch 7 years, 1 month ago
Failed in applying to current master (apply log)
There is a newer version of this series
MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
[edk2] [patch] MdeModulePkg/HiiDatabase: clean the value before setting default string
Posted by Dandan Bi 7 years, 1 month ago
For string op-code, the default string may not exceed the
maximum size, so when generating <AltResp> string, we should
clean the value before setting the default string.

https://bugzilla.tianocore.org/show_bug.cgi?id=375

Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
---
 MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
index d547f42..1878106 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
@@ -1,9 +1,9 @@
 /** @file
 Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.
 
-Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 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
 http://opensource.org/licenses/bsd-license.php
 
@@ -3696,21 +3696,29 @@ GenerateAltConfigResp (
         // Convert Value to a hex string in "%x" format
         // NOTE: This is in the opposite byte that GUID and PATH use
         //
         if (BlockData->OpCode == EFI_IFR_STRING_OP){
           DefaultString   = InternalGetString(HiiHandle, DefaultValueData->Value.string);
-          TmpBuffer = (UINT8 *) DefaultString;
+          TmpBuffer = AllocateZeroPool (Width);
+          ASSERT (TmpBuffer != NULL);
+          if (DefaultString != NULL) {
+            CopyMem (TmpBuffer, (UINT8 *) DefaultString, StrLen(DefaultString)* sizeof (CHAR16));
+          }
         } else {
           TmpBuffer = (UINT8 *) &(DefaultValueData->Value);
         }
         for (; Width > 0 && (TmpBuffer != NULL); Width--) {
           StringPtr += UnicodeValueToString (StringPtr, PREFIX_ZERO | RADIX_HEX, TmpBuffer[Width - 1], 2);
         }
         if (DefaultString != NULL){
           FreePool(DefaultString);
           DefaultString = NULL;
         }
+        if (BlockData->OpCode == EFI_IFR_STRING_OP && TmpBuffer != NULL) {
+          FreePool(TmpBuffer);
+          TmpBuffer  = NULL;
+        }
       }
     }
   }
 
   HiiToLower (*DefaultAltCfgResp);
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [patch] MdeModulePkg/HiiDatabase: clean the value before setting default string
Posted by Dong, Eric 7 years, 1 month ago
Dandan,

You need to also add check to avoid string size exceed the width.

Thanks,
Eric

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Dandan Bi
> Sent: Monday, February 20, 2017 1:06 PM
> To: edk2-devel@lists.01.org
> Cc: Dong, Eric; Gao, Liming
> Subject: [edk2] [patch] MdeModulePkg/HiiDatabase: clean the value before setting default string
> 
> For string op-code, the default string may not exceed the
> maximum size, so when generating <AltResp> string, we should
> clean the value before setting the default string.
> 
> https://bugzilla.tianocore.org/show_bug.cgi?id=375
> 
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Dandan Bi <dandan.bi@intel.com>
> ---
>  MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
> index d547f42..1878106 100644
> --- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
> +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
> @@ -1,9 +1,9 @@
>  /** @file
>  Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL.
> 
> -Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
>  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
>  http://opensource.org/licenses/bsd-license.php
> 
> @@ -3696,21 +3696,29 @@ GenerateAltConfigResp (
>          // Convert Value to a hex string in "%x" format
>          // NOTE: This is in the opposite byte that GUID and PATH use
>          //
>          if (BlockData->OpCode == EFI_IFR_STRING_OP){
>            DefaultString   = InternalGetString(HiiHandle, DefaultValueData->Value.string);
> -          TmpBuffer = (UINT8 *) DefaultString;
> +          TmpBuffer = AllocateZeroPool (Width);
> +          ASSERT (TmpBuffer != NULL);
> +          if (DefaultString != NULL) {
> +            CopyMem (TmpBuffer, (UINT8 *) DefaultString, StrLen(DefaultString)* sizeof (CHAR16));
> +          }
>          } else {
>            TmpBuffer = (UINT8 *) &(DefaultValueData->Value);
>          }
>          for (; Width > 0 && (TmpBuffer != NULL); Width--) {
>            StringPtr += UnicodeValueToString (StringPtr, PREFIX_ZERO | RADIX_HEX, TmpBuffer[Width - 1], 2);
>          }
>          if (DefaultString != NULL){
>            FreePool(DefaultString);
>            DefaultString = NULL;
>          }
> +        if (BlockData->OpCode == EFI_IFR_STRING_OP && TmpBuffer != NULL) {
> +          FreePool(TmpBuffer);
> +          TmpBuffer  = NULL;
> +        }
>        }
>      }
>    }
> 
>    HiiToLower (*DefaultAltCfgResp);
> --
> 1.9.5.msysgit.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel