diff options
author | Jian J Wang <jian.j.wang@intel.com> | 2018-01-22 13:06:08 +0800 |
---|---|---|
committer | Ruiyu Ni <ruiyu.ni@intel.com> | 2018-01-25 10:24:21 +0800 |
commit | c3492bd9bb464ea1dcb3601c43a7dd941bdcb254 (patch) | |
tree | dd45e72e22a496f26b941f658b0fe09151d93f22 /ShellPkg/Library | |
parent | bac7f02365b1d24cc6ac93fe853a25ebb8df6efe (diff) | |
download | edk2-c3492bd9bb464ea1dcb3601c43a7dd941bdcb254.tar.gz edk2-c3492bd9bb464ea1dcb3601c43a7dd941bdcb254.tar.bz2 edk2-c3492bd9bb464ea1dcb3601c43a7dd941bdcb254.zip |
ShellPkg/UefiShellLevel3CommandsLib: fix string over-read
In the for-loop condition of original code, the expression
*CurrentCommand != CHAR_NULL
is put before expression
CurrentCommand < SortedCommandList + SortedCommandListSize/sizeof(CHAR16)
When CurrentCommand walks to the end of string buffer, one more character
over the end of string buffer will be read and then stop.
To fix this issue, just move the last expression to the first one. Because
of short-circuit evaludation of and-expression, the following one
*CurrentCommand != CHAR_NULL
will not be evaluated if the expression before it is evaludated as FALSE.
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Diffstat (limited to 'ShellPkg/Library')
-rw-r--r-- | ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c b/ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c index a71ade3a20..f6159c1335 100644 --- a/ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c +++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c @@ -397,7 +397,7 @@ ShellCommandRunHelp ( CopyListOfCommandNamesWithDynamic(&SortedCommandList, &SortedCommandListSize);
for (CurrentCommand = SortedCommandList
- ; CurrentCommand != NULL && *CurrentCommand != CHAR_NULL && CurrentCommand < SortedCommandList + SortedCommandListSize/sizeof(CHAR16)
+ ; CurrentCommand != NULL && CurrentCommand < SortedCommandList + SortedCommandListSize/sizeof(CHAR16) && *CurrentCommand != CHAR_NULL
; CurrentCommand += StrLen(CurrentCommand) + 1
) {
//
|