]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg/UefiShellLevel3CommandsLib: fix string over-read
authorJian J Wang <jian.j.wang@intel.com>
Mon, 22 Jan 2018 05:06:08 +0000 (13:06 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Thu, 25 Jan 2018 02:24:21 +0000 (10:24 +0800)
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>
ShellPkg/Library/UefiShellLevel3CommandsLib/Help.c

index a71ade3a20cc43fa0d9e47a95f269dbc53ed2175..f6159c133585b67c5ab208c53e3e5364a1a414e6 100644 (file)
@@ -397,7 +397,7 @@ ShellCommandRunHelp (
         CopyListOfCommandNamesWithDynamic(&SortedCommandList, &SortedCommandListSize);\r
 \r
         for (CurrentCommand = SortedCommandList \r
-          ; CurrentCommand != NULL && *CurrentCommand != CHAR_NULL && CurrentCommand < SortedCommandList + SortedCommandListSize/sizeof(CHAR16)\r
+          ; CurrentCommand != NULL && CurrentCommand < SortedCommandList + SortedCommandListSize/sizeof(CHAR16) && *CurrentCommand != CHAR_NULL\r
           ; CurrentCommand += StrLen(CurrentCommand) + 1\r
           ) {\r
           //\r