https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6a3a79bb721f9e3496769…
commit 6a3a79bb721f9e34967693f3f8dfc8a4b26ec95c
Author: Marcin Jabłoński <24442148+TheNNX(a)users.noreply.github.com>
AuthorDate: Sat Nov 12 13:02:33 2022 +0100
Commit: GitHub <noreply(a)github.com>
CommitDate: Sat Nov 12 13:02:33 2022 +0100
[DISKPART] Fix help for multi-word command crashing. (#4873)
* [DISKPART] Fix help for multi-word command crashing.
When the HELP command is executed for a multi-word command,
for example "HELP CREATE PARTITION PRIMARY", diskpart crashes.
This happens because before the desired form of the command
is encountered, its single word form is found - since the first word
of the command matches the one HELP is looking for, it tries to
compare the second word of the input command with the second
(nonexistent) word of the encountered single word command,
which is NULL. This results in diskpart crashing.
The fix makes HELP check if the to-be-compared word is not NULL,
before calling wcsicmp.
---
base/system/diskpart/help.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/base/system/diskpart/help.c b/base/system/diskpart/help.c
index 2caf271e5f2..0e20175e10c 100644
--- a/base/system/diskpart/help.c
+++ b/base/system/diskpart/help.c
@@ -60,7 +60,7 @@ HelpCommand(
{
if (pCommand->cmd1 != NULL && pCommand->cmd2 == NULL &&
pCommand->cmd3 == NULL)
{
- if ((wcsicmp(pCommand->cmd1, cmdptr->cmd1) == 0) &&
+ if ((cmdptr->cmd1 != NULL && wcsicmp(pCommand->cmd1,
cmdptr->cmd1) == 0) &&
(cmdptr->cmd2 != NULL) &&
(cmdptr->cmd3 == NULL) &&
(cmdptr->help != IDS_NONE))
@@ -72,8 +72,8 @@ HelpCommand(
}
else if (pCommand->cmd1 != NULL && pCommand->cmd2 != NULL
&& pCommand->cmd3 == NULL)
{
- if ((wcsicmp(pCommand->cmd1, cmdptr->cmd1) == 0) &&
- (wcsicmp(pCommand->cmd2, cmdptr->cmd2) == 0) &&
+ if ((cmdptr->cmd1 != NULL && wcsicmp(pCommand->cmd1,
cmdptr->cmd1) == 0) &&
+ (cmdptr->cmd2 != NULL && wcsicmp(pCommand->cmd2,
cmdptr->cmd2) == 0) &&
(cmdptr->cmd3 != NULL) &&
(cmdptr->help != IDS_NONE))
{
@@ -84,9 +84,9 @@ HelpCommand(
}
else if (pCommand->cmd1 != NULL && pCommand->cmd2 != NULL
&& pCommand->cmd3 != NULL)
{
- if ((wcsicmp(pCommand->cmd1, cmdptr->cmd1) == 0) &&
- (wcsicmp(pCommand->cmd2, cmdptr->cmd2) == 0) &&
- (wcsicmp(pCommand->cmd3, cmdptr->cmd3) == 0) &&
+ if ((cmdptr->cmd1 != NULL && wcsicmp(pCommand->cmd1,
cmdptr->cmd1) == 0) &&
+ (cmdptr->cmd2 != NULL && wcsicmp(pCommand->cmd2,
cmdptr->cmd2) == 0) &&
+ (cmdptr->cmd3 != NULL && wcsicmp(pCommand->cmd3,
cmdptr->cmd3) == 0) &&
(cmdptr->help_detail != MSG_NONE))
{
ConMsgPuts(StdOut,
@@ -134,21 +134,27 @@ BOOL help_main(INT argc, LPWSTR *argv)
for (cmdptr = cmds; cmdptr->cmd1; cmdptr++)
{
if ((cmdptr1 == NULL) &&
- (wcsicmp(argv[1], cmdptr->cmd1) == 0))
+ (cmdptr->cmd1 != NULL && wcsicmp(argv[1], cmdptr->cmd1) == 0))
+ {
cmdptr1 = cmdptr;
+ }
if ((cmdptr2 == NULL) &&
(argc >= 3) &&
- (wcsicmp(argv[1], cmdptr->cmd1) == 0) &&
- (wcsicmp(argv[2], cmdptr->cmd2) == 0))
+ (cmdptr->cmd1 != NULL && wcsicmp(argv[1], cmdptr->cmd1) == 0)
&&
+ (cmdptr->cmd2 != NULL && wcsicmp(argv[2], cmdptr->cmd2) == 0))
+ {
cmdptr2 = cmdptr;
-
+ }
+
if ((cmdptr3 == NULL) &&
(argc >= 4) &&
- (wcsicmp(argv[1], cmdptr->cmd1) == 0) &&
- (wcsicmp(argv[2], cmdptr->cmd2) == 0) &&
- (wcsicmp(argv[3], cmdptr->cmd3) == 0))
+ (cmdptr->cmd1 != NULL && wcsicmp(argv[1], cmdptr->cmd1) == 0)
&&
+ (cmdptr->cmd2 != NULL && wcsicmp(argv[2], cmdptr->cmd2) == 0)
&&
+ (cmdptr->cmd3 != NULL && wcsicmp(argv[3], cmdptr->cmd3) == 0))
+ {
cmdptr3 = cmdptr;
+ }
}
if (cmdptr3 != NULL)