public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2] MdeModulePkg/HiiDatabase: clean the value before setting default string
@ 2017-02-21  2:26 Dandan Bi
  2017-02-21  8:20 ` Dong, Eric
  0 siblings, 1 reply; 2+ messages in thread
From: Dandan Bi @ 2017-02-21  2:26 UTC (permalink / raw)
  To: edk2-devel; +Cc: Eric Dong, Liming Gao

For string op-code, the default string may not reach the
maximum size, so when generating <AltResp> string, we should
clean the value before setting the default string.

V2: Add check for default string size.

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 | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
index d547f42..ccf4b5a 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
 
@@ -3579,10 +3579,11 @@ GenerateAltConfigResp (
   IFR_DEFAULT_DATA      *DefaultId;
   IFR_DEFAULT_DATA      *DefaultValueData;
   UINTN                 Width;
   UINT8                 *TmpBuffer;
   CHAR16                *DefaultString;
+  UINTN                 StrSize;
 
   BlockData     = NULL;
   DataExist     = FALSE;
   DefaultString = NULL;
   //
@@ -3696,21 +3697,33 @@ 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) {
+            StrSize = StrLen(DefaultString)* sizeof (CHAR16);
+            if (StrSize > Width) {
+              StrSize = Width;
+            }
+            CopyMem (TmpBuffer, (UINT8 *) DefaultString, StrSize);
+          }
         } 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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] MdeModulePkg/HiiDatabase: clean the value before setting default string
  2017-02-21  2:26 [PATCH v2] MdeModulePkg/HiiDatabase: clean the value before setting default string Dandan Bi
@ 2017-02-21  8:20 ` Dong, Eric
  0 siblings, 0 replies; 2+ messages in thread
From: Dong, Eric @ 2017-02-21  8:20 UTC (permalink / raw)
  To: Bi, Dandan, edk2-devel@lists.01.org; +Cc: Gao, Liming

Reviewed-by: Eric Dong <eric.dong@intel.com>

> -----Original Message-----
> From: Bi, Dandan
> Sent: Tuesday, February 21, 2017 10:26 AM
> To: edk2-devel@lists.01.org
> Cc: Dong, Eric; Gao, Liming
> Subject: [PATCH v2] MdeModulePkg/HiiDatabase: clean the value before setting default string
> 
> For string op-code, the default string may not reach the
> maximum size, so when generating <AltResp> string, we should
> clean the value before setting the default string.
> 
> V2: Add check for default string size.
> 
> 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 | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c
> index d547f42..ccf4b5a 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
> 
> @@ -3579,10 +3579,11 @@ GenerateAltConfigResp (
>    IFR_DEFAULT_DATA      *DefaultId;
>    IFR_DEFAULT_DATA      *DefaultValueData;
>    UINTN                 Width;
>    UINT8                 *TmpBuffer;
>    CHAR16                *DefaultString;
> +  UINTN                 StrSize;
> 
>    BlockData     = NULL;
>    DataExist     = FALSE;
>    DefaultString = NULL;
>    //
> @@ -3696,21 +3697,33 @@ 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) {
> +            StrSize = StrLen(DefaultString)* sizeof (CHAR16);
> +            if (StrSize > Width) {
> +              StrSize = Width;
> +            }
> +            CopyMem (TmpBuffer, (UINT8 *) DefaultString, StrSize);
> +          }
>          } 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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-02-21  8:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-21  2:26 [PATCH v2] MdeModulePkg/HiiDatabase: clean the value before setting default string Dandan Bi
2017-02-21  8:20 ` Dong, Eric

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox