Reviewed-by: Liming Gao <liming....@intel.com>

> -----Original Message-----
> From: Bi, Dandan
> Sent: Thursday, May 12, 2016 2:23 PM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming <liming....@intel.com>; Dong, Eric <eric.d...@intel.com>
> Subject: [patch] MdeModulePkg/SetupBrowser: Clean the BufferValue for
> string before use
> 
> When copy new string content to BufferValue, need to clean the
> BufferValue firstly, or the BufferValue may contain some
> content that doesn't belong to the new string.
> 
> Cc: Liming Gao <liming....@intel.com>
> Cc: Eric Dong <eric.d...@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Dandan Bi <dandan...@intel.com>
> ---
>  MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c | 4 +++-
>  MdeModulePkg/Universal/SetupBrowserDxe/Setup.c        | 2 ++
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
> b/MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
> index 4c4e51d..56ae7b0 100644
> --- a/MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
> +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
> @@ -1,9 +1,9 @@
>  /** @file
>  Utility functions for UI presentation.
> 
> -Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
>  (C) Copyright 2015 Hewlett Packard Enterprise Development LP<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
> @@ -2042,10 +2042,11 @@ ProcessCallBackFunction (
>          NewString = GetToken (Statement->HiiValue.Value.string, FormSet-
> >HiiHandle);
>          ASSERT (NewString != NULL);
> 
>          ASSERT (StrLen (NewString) * sizeof (CHAR16) <= Statement-
> >StorageWidth);
>          if (StrLen (NewString) * sizeof (CHAR16) <= Statement->StorageWidth) 
> {
> +          ZeroMem (Statement->BufferValue, Statement->StorageWidth);
>            CopyMem (Statement->BufferValue, NewString, StrSize (NewString));
>          } else {
>            CopyMem (Statement->BufferValue, NewString, Statement-
> >StorageWidth);
>          }
>          FreePool (NewString);
> @@ -2291,10 +2292,11 @@ ProcessRetrieveForQuestion (
>      NewString = GetToken (Statement->HiiValue.Value.string, FormSet-
> >HiiHandle);
>      ASSERT (NewString != NULL);
> 
>      ASSERT (StrLen (NewString) * sizeof (CHAR16) <= Statement-
> >StorageWidth);
>      if (StrLen (NewString) * sizeof (CHAR16) <= Statement->StorageWidth) {
> +      ZeroMem (Statement->BufferValue, Statement->StorageWidth);
>        CopyMem (Statement->BufferValue, NewString, StrSize (NewString));
>      } else {
>        CopyMem (Statement->BufferValue, NewString, Statement-
> >StorageWidth);
>      }
>      FreePool (NewString);
> diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
> b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
> index 23094f8..0f45d0c 100644
> --- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
> +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
> @@ -4097,10 +4097,11 @@ GetQuestionDefault (
>          NewString = GetToken (Question->HiiValue.Value.string, FormSet-
> >HiiHandle);
>          ASSERT (NewString != NULL);
> 
>          ASSERT (StrLen (NewString) * sizeof (CHAR16) <= Question-
> >StorageWidth);
>          if (StrLen (NewString) * sizeof (CHAR16) <= Question->StorageWidth) {
> +          ZeroMem (Question->BufferValue, Question->StorageWidth);
>            CopyMem (Question->BufferValue, NewString, StrSize (NewString));
>          } else {
>            CopyMem (Question->BufferValue, NewString, Question-
> >StorageWidth);
>          }
> 
> @@ -4167,10 +4168,11 @@ GetQuestionDefault (
>            StrValue = HiiGetString (FormSet->HiiHandle, 
> HiiValue->Value.string,
> NULL);
>            if (StrValue == NULL) {
>              return EFI_NOT_FOUND;
>            }
>            if (Question->StorageWidth > StrSize (StrValue)) {
> +            ZeroMem (Question->BufferValue, Question->StorageWidth);
>              CopyMem (Question->BufferValue, StrValue, StrSize (StrValue));
>            } else {
>              CopyMem (Question->BufferValue, StrValue, Question-
> >StorageWidth);
>            }
>          }
> --
> 1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to