[edk2] [PATCH] ShellPkg/UefiShellLib: Avoid reading undefined content before string

Hao Wu posted 1 patch 7 years, 7 months ago
Failed in applying to current master (apply log)
ShellPkg/Library/UefiShellLib/UefiShellLib.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[edk2] [PATCH] ShellPkg/UefiShellLib: Avoid reading undefined content before string
Posted by Hao Wu 7 years, 7 months ago
https://bugzilla.tianocore.org/show_bug.cgi?id=566

In function InternalShellPrintWorker(), if the string in variable
'mPostReplaceFormat2' starts with character L'%', the following
expression:

*(ResumeLocation-1) == L'^' at line 2831

will read an undefined value before the starting of string
'mPostReplaceFormat2'.

This commit adds additional logic to avoid reading undefined content.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 ShellPkg/Library/UefiShellLib/UefiShellLib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
index 55e8a67ac4..25706e9bc3 100644
--- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
+++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
@@ -2828,7 +2828,7 @@ InternalShellPrintWorker(
     // update the attribute
     //
     if (ResumeLocation != NULL) {
-      if (*(ResumeLocation-1) == L'^') {
+      if ((ResumeLocation != mPostReplaceFormat2) && (*(ResumeLocation-1) == L'^')) {
         //
         // Move cursor back 1 position to overwrite the ^
         //
-- 
2.12.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] ShellPkg/UefiShellLib: Avoid reading undefined content before string
Posted by Carsey, Jaben 7 years, 7 months ago
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

> -----Original Message-----
> From: Wu, Hao A
> Sent: Monday, May 22, 2017 7:04 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Ni, Ruiyu <ruiyu.ni@intel.com>;
> Carsey, Jaben <jaben.carsey@intel.com>
> Subject: [PATCH] ShellPkg/UefiShellLib: Avoid reading undefined content
> before string
> Importance: High
> 
> https://bugzilla.tianocore.org/show_bug.cgi?id=566
> 
> In function InternalShellPrintWorker(), if the string in variable
> 'mPostReplaceFormat2' starts with character L'%', the following
> expression:
> 
> *(ResumeLocation-1) == L'^' at line 2831
> 
> will read an undefined value before the starting of string
> 'mPostReplaceFormat2'.
> 
> This commit adds additional logic to avoid reading undefined content.
> 
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Jaben Carsey <jaben.carsey@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Hao Wu <hao.a.wu@intel.com>
> ---
>  ShellPkg/Library/UefiShellLib/UefiShellLib.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> index 55e8a67ac4..25706e9bc3 100644
> --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> @@ -2828,7 +2828,7 @@ InternalShellPrintWorker(
>      // update the attribute
>      //
>      if (ResumeLocation != NULL) {
> -      if (*(ResumeLocation-1) == L'^') {
> +      if ((ResumeLocation != mPostReplaceFormat2) && (*(ResumeLocation-
> 1) == L'^')) {
>          //
>          // Move cursor back 1 position to overwrite the ^
>          //
> --
> 2.12.0.windows.1

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