From e99d532fd7224e68026543834ed9c0fe3cfaf88c Mon Sep 17 00:00:00 2001 From: Tormod Volden Date: Wed, 24 Jul 2024 00:22:29 +0200 Subject: [PATCH] ShellPkg/UefiShellLib: Accept "0 " as valid numeric string InternalShellIsHexOrDecimalNumber() would fail to interpret e.g. "0 " or "00 " as valid numeric strings. After skipping the "0" digits as leading zeroes, it would check if the next character is a valid hex or decimal digit, which would then fail on the terminating character. Therefore return success if "leading" zeroes have been consumed and there are no more characters. InternalShellStrHexToUint64() would fail to interpret e.g. "0 " or "00 " as valid numeric strings. After skipping the "0" digits as leading zeroes, it would find itself surprised by the following space. Restrict the "bad space" check to the case where it had just consumed the "x" or "X" marker. Otherwise the space is fine (depending on StopAtSpace either end of number or interspersed space) since there were only zeroes so far. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3080 Signed-off-by: Tormod Volden --- ShellPkg/Library/UefiShellLib/UefiShellLib.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c index 9dde9fddfa..e68c978642 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -3894,6 +3894,10 @@ InternalShellIsHexOrDecimalNumber ( Hex = FALSE; } + if ((*String == CHAR_NULL) && LeadingZero) { + return (TRUE); + } + // // loop through the remaining characters and use the lib function // @@ -4041,17 +4045,17 @@ InternalShellStrHexToUint64 ( // Skip the 'X' // String++; + + // + // there is a space where there should't be + // + if (*String == L' ') { + return (EFI_INVALID_PARAMETER); + } } Result = 0; - // - // there is a space where there should't be - // - if (*String == L' ') { - return (EFI_INVALID_PARAMETER); - } - while (ShellIsHexaDecimalDigitCharacter (*String)) { // // If the Hex Number represented by String overflows according