]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/ShellLib: Fix a bug in InternalShellIsHexOrDecimalNumber
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 13 Feb 2018 08:39:31 +0000 (15:39 +0700)
committerRuiyu Ni <ruiyu.ni@intel.com>
Thu, 15 Feb 2018 06:12:52 +0000 (14:12 +0800)
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>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
ShellPkg/Library/UefiShellLib/UefiShellLib.c

index 7f6389f655783a7a68156490c2118b9c0e8cf5d7..e53985e2d71406a45970fd618927f36e280dc0a9 100644 (file)
@@ -3,7 +3,7 @@
 \r
   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
   Copyright 2016 Dell Inc.\r
 \r
   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
   Copyright 2016 Dell Inc.\r
-  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -3636,29 +3636,36 @@ InternalShellIsHexOrDecimalNumber (
   )\r
 {\r
   BOOLEAN Hex;\r
   )\r
 {\r
   BOOLEAN Hex;\r
+  BOOLEAN LeadingZero;\r
+\r
+  if (String == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   //\r
   // chop off a single negative sign\r
   //\r
 \r
   //\r
   // chop off a single negative sign\r
   //\r
-  if (String != NULL && *String == L'-') {\r
+  if (*String == L'-') {\r
     String++;\r
   }\r
 \r
     String++;\r
   }\r
 \r
-  if (String == NULL) {\r
-    return (FALSE);\r
+  if (*String == CHAR_NULL) {\r
+    return FALSE;\r
   }\r
 \r
   //\r
   // chop leading zeroes\r
   //\r
   }\r
 \r
   //\r
   // chop leading zeroes\r
   //\r
-  while(String != NULL && *String == L'0'){\r
+  LeadingZero = FALSE;\r
+  while(*String == L'0'){\r
     String++;\r
     String++;\r
+    LeadingZero = TRUE;\r
   }\r
   //\r
   // allow '0x' or '0X', but not 'x' or 'X'\r
   //\r
   }\r
   //\r
   // allow '0x' or '0X', but not 'x' or 'X'\r
   //\r
-  if (String != NULL && (*String == L'x' || *String == L'X')) {\r
-    if (*(String-1) != L'0') {\r
+  if (*String == L'x' || *String == L'X') {\r
+    if (!LeadingZero) {\r
       //\r
       // we got an x without a preceeding 0\r
       //\r
       //\r
       // we got an x without a preceeding 0\r
       //\r
@@ -3675,7 +3682,7 @@ InternalShellIsHexOrDecimalNumber (
   //\r
   // loop through the remaining characters and use the lib function\r
   //\r
   //\r
   // loop through the remaining characters and use the lib function\r
   //\r
-  for ( ; String != NULL && *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){\r
+  for ( ; *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){\r
     if (TimeNumbers && (String[0] == L':')) {\r
       continue;\r
     }\r
     if (TimeNumbers && (String[0] == L':')) {\r
       continue;\r
     }\r