[edk2] [PATCH] ShellPkg/ShellLib: Fix a bug in InternalShellIsHexOrDecimalNumber

Ruiyu Ni posted 1 patch 6 years, 2 months ago
Failed in applying to current master (apply log)
ShellPkg/Library/UefiShellLib/UefiShellLib.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
[edk2] [PATCH] ShellPkg/ShellLib: Fix a bug in InternalShellIsHexOrDecimalNumber
Posted by Ruiyu Ni 6 years, 2 months ago
InternalShellIsHexOrDecimalNumber() wrongly treats "-" as a number.
The patch fixes this issue.

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

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Vladimir Olovyannikov <vladimir.olovyannikov@broadcom.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
---
 ShellPkg/Library/UefiShellLib/UefiShellLib.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
index 7f6389f655..e53985e2d7 100644
--- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
+++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
@@ -3,7 +3,7 @@
 
   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
   Copyright 2016 Dell Inc.
-  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2018, 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
@@ -3636,29 +3636,36 @@ InternalShellIsHexOrDecimalNumber (
   )
 {
   BOOLEAN Hex;
+  BOOLEAN LeadingZero;
+
+  if (String == NULL) {
+    return FALSE;
+  }
 
   //
   // chop off a single negative sign
   //
-  if (String != NULL && *String == L'-') {
+  if (*String == L'-') {
     String++;
   }
 
-  if (String == NULL) {
-    return (FALSE);
+  if (*String == CHAR_NULL) {
+    return FALSE;
   }
 
   //
   // chop leading zeroes
   //
-  while(String != NULL && *String == L'0'){
+  LeadingZero = FALSE;
+  while(*String == L'0'){
     String++;
+    LeadingZero = TRUE;
   }
   //
   // allow '0x' or '0X', but not 'x' or 'X'
   //
-  if (String != NULL && (*String == L'x' || *String == L'X')) {
-    if (*(String-1) != L'0') {
+  if (*String == L'x' || *String == L'X') {
+    if (!LeadingZero) {
       //
       // we got an x without a preceeding 0
       //
@@ -3675,7 +3682,7 @@ InternalShellIsHexOrDecimalNumber (
   //
   // loop through the remaining characters and use the lib function
   //
-  for ( ; String != NULL && *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){
+  for ( ; *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){
     if (TimeNumbers && (String[0] == L':')) {
       continue;
     }
-- 
2.16.1.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] ShellPkg/ShellLib: Fix a bug in InternalShellIsHexOrDecimalNumber
Posted by Carsey, Jaben 6 years, 2 months ago
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

> -----Original Message-----
> From: Ni, Ruiyu
> Sent: Tuesday, February 13, 2018 12:54 AM
> To: edk2-devel@lists.01.org
> Cc: Vladimir Olovyannikov <vladimir.olovyannikov@broadcom.com>; Carsey,
> Jaben <jaben.carsey@intel.com>
> Subject: [PATCH] ShellPkg/ShellLib: Fix a bug in
> InternalShellIsHexOrDecimalNumber
> Importance: High
> 
> InternalShellIsHexOrDecimalNumber() wrongly treats "-" as a number.
> The patch fixes this issue.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=730
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Vladimir Olovyannikov <vladimir.olovyannikov@broadcom.com>
> Cc: Jaben Carsey <jaben.carsey@intel.com>
> ---
>  ShellPkg/Library/UefiShellLib/UefiShellLib.c | 23 +++++++++++++++--------
>  1 file changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> index 7f6389f655..e53985e2d7 100644
> --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
> @@ -3,7 +3,7 @@
> 
>    (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
>    Copyright 2016 Dell Inc.
> -  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2006 - 2018, 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
> @@ -3636,29 +3636,36 @@ InternalShellIsHexOrDecimalNumber (
>    )
>  {
>    BOOLEAN Hex;
> +  BOOLEAN LeadingZero;
> +
> +  if (String == NULL) {
> +    return FALSE;
> +  }
> 
>    //
>    // chop off a single negative sign
>    //
> -  if (String != NULL && *String == L'-') {
> +  if (*String == L'-') {
>      String++;
>    }
> 
> -  if (String == NULL) {
> -    return (FALSE);
> +  if (*String == CHAR_NULL) {
> +    return FALSE;
>    }
> 
>    //
>    // chop leading zeroes
>    //
> -  while(String != NULL && *String == L'0'){
> +  LeadingZero = FALSE;
> +  while(*String == L'0'){
>      String++;
> +    LeadingZero = TRUE;
>    }
>    //
>    // allow '0x' or '0X', but not 'x' or 'X'
>    //
> -  if (String != NULL && (*String == L'x' || *String == L'X')) {
> -    if (*(String-1) != L'0') {
> +  if (*String == L'x' || *String == L'X') {
> +    if (!LeadingZero) {
>        //
>        // we got an x without a preceeding 0
>        //
> @@ -3675,7 +3682,7 @@ InternalShellIsHexOrDecimalNumber (
>    //
>    // loop through the remaining characters and use the lib function
>    //
> -  for ( ; String != NULL && *String != CHAR_NULL && !(StopAtSpace &&
> *String == L' ') ; String++){
> +  for ( ; *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ;
> String++){
>      if (TimeNumbers && (String[0] == L':')) {
>        continue;
>      }
> --
> 2.16.1.windows.1

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