summaryrefslogtreecommitdiff
path: root/ShellPkg
diff options
context:
space:
mode:
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2011-10-14 19:21:13 +0000
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2011-10-14 19:21:13 +0000
commit532691c8ba90e5022174503ab0781322c6f79cab (patch)
tree7c598451898c979b99cdfa0ec1573d509d5ee1ff /ShellPkg
parentde2a15eebbf467c335f3e28ff0ba0ca6dd0ddcf2 (diff)
downloadedk2-platforms-532691c8ba90e5022174503ab0781322c6f79cab.tar.xz
ShellPkg: Add checking for memory allocation and pointer returns from functions.
signed-off-by: jcarsey reviewed-by: geekboy15a git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12540 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg')
-rw-r--r--ShellPkg/Application/Shell/Shell.c29
-rw-r--r--ShellPkg/Application/Shell/ShellManParser.c16
-rw-r--r--ShellPkg/Application/Shell/ShellParametersProtocol.c24
-rw-r--r--ShellPkg/Application/Shell/ShellProtocol.c25
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c2
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c1
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c3
-rw-r--r--ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c2
-rw-r--r--ShellPkg/Library/UefiShellLevel1CommandsLib/For.c285
-rw-r--r--ShellPkg/Library/UefiShellLevel1CommandsLib/If.c3
-rw-r--r--ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c4
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c3
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c7
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c4
-rw-r--r--ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c11
15 files changed, 252 insertions, 167 deletions
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c
index 614c1e9595..d266c826e9 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -857,15 +857,19 @@ DoStartupScript(
FileStringPath = NULL;
NewSize = 0;
FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, MapName, 0);
- TempSpot = StrStr(FileStringPath, L";");
- if (TempSpot != NULL) {
- *TempSpot = CHAR_NULL;
+ if (FileStringPath == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ TempSpot = StrStr(FileStringPath, L";");
+ if (TempSpot != NULL) {
+ *TempSpot = CHAR_NULL;
+ }
+ FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);
+ PathRemoveLastItem(FileStringPath);
+ FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);
+ Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);
+ FreePool(FileStringPath);
}
- FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);
- PathRemoveLastItem(FileStringPath);
- FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);
- Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);
- FreePool(FileStringPath);
}
if (EFI_ERROR(Status)) {
NamePath = FileDevicePath (NULL, mStartupScript);
@@ -1215,6 +1219,12 @@ RunSplitCommand(
NextCommandLine = StrnCatGrow(&NextCommandLine, &Size1, StrStr(CmdLine, L"|")+1, 0);
OurCommandLine = StrnCatGrow(&OurCommandLine , &Size2, CmdLine , StrStr(CmdLine, L"|") - CmdLine);
+
+ if (NextCommandLine == NULL || OurCommandLine == NULL) {
+ SHELL_FREE_NON_NULL(OurCommandLine);
+ SHELL_FREE_NON_NULL(NextCommandLine);
+ return (EFI_OUT_OF_RESOURCES);
+ }
if (NextCommandLine[0] != CHAR_NULL &&
NextCommandLine[0] == L'a' &&
NextCommandLine[1] == L' '
@@ -1334,6 +1344,9 @@ RunCommand(
Split = NULL;
CleanOriginal = StrnCatGrow(&CleanOriginal, NULL, CmdLine, 0);
+ if (CleanOriginal == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
while (CleanOriginal[StrLen(CleanOriginal)-1] == L' ') {
CleanOriginal[StrLen(CleanOriginal)-1] = CHAR_NULL;
}
diff --git a/ShellPkg/Application/Shell/ShellManParser.c b/ShellPkg/Application/Shell/ShellManParser.c
index bd2efcb423..470f51a8ea 100644
--- a/ShellPkg/Application/Shell/ShellManParser.c
+++ b/ShellPkg/Application/Shell/ShellManParser.c
@@ -180,6 +180,10 @@ ManBufferFindSections(
TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));
ASSERT(TempString == NULL);
TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);
+ if (TempString == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ break;
+ }
SectionName = TempString;
SectionLen = StrLen(SectionName);
SectionName = StrStr(Sections, SectionName);
@@ -197,12 +201,24 @@ ManBufferFindSections(
TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));
ASSERT(TempString == NULL);
TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);
+ if (TempString == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ break;
+ }
//
// copy and save the current line.
//
ASSERT((*HelpText == NULL && *HelpSize == 0) || (*HelpText != NULL));
StrnCatGrow (HelpText, HelpSize, TempString, 0);
+ if (HelpText == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ break;
+ }
StrnCatGrow (HelpText, HelpSize, L"\r\n", 0);
+ if (HelpText == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ break;
+ }
}
}
SHELL_FREE_NON_NULL(TempString);
diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c
index 5beaadab2e..55cf3c279e 100644
--- a/ShellPkg/Application/Shell/ShellParametersProtocol.c
+++ b/ShellPkg/Application/Shell/ShellParametersProtocol.c
@@ -577,6 +577,9 @@ UpdateStdInStdOutStdErr(
}
CommandLineCopy = StrnCatGrow(&CommandLineCopy, NULL, NewCommandLine, 0);
+ if (CommandLineCopy == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
Status = EFI_SUCCESS;
Split = NULL;
FirstLocation = CommandLineCopy + StrLen(CommandLineCopy);
@@ -1030,16 +1033,19 @@ UpdateStdInStdOutStdErr(
//
if (!EFI_ERROR(Status) && StdInVarName != NULL) {
TempHandle = CreateFileInterfaceEnv(StdInVarName);
- if (!InUnicode) {
- TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
- }
- Size = 0;
- ASSERT(TempHandle != NULL);
- if (((EFI_FILE_PROTOCOL*)TempHandle)->Read(TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL) {
- Status = EFI_INVALID_PARAMETER;
+ if (TempHandle == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
} else {
- ShellParameters->StdIn = TempHandle;
- gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle);
+ if (!InUnicode) {
+ TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
+ }
+ Size = 0;
+ if (((EFI_FILE_PROTOCOL*)TempHandle)->Read(TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL) {
+ Status = EFI_INVALID_PARAMETER;
+ } else {
+ ShellParameters->StdIn = TempHandle;
+ gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle);
+ }
}
}
diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c
index de7dc3cad9..6b81918101 100644
--- a/ShellPkg/Application/Shell/ShellProtocol.c
+++ b/ShellPkg/Application/Shell/ShellProtocol.c
@@ -488,10 +488,12 @@ EfiShellGetFilePathFromDevicePath(
This function converts a file system style name to a device path, by replacing any
mapping references to the associated device path.
- @param Path the pointer to the path
+ @param[in] Path The pointer to the path.
- @return all The pointer of the file path. The file path is callee
+ @return The pointer of the file path. The file path is callee
allocated and should be freed by the caller.
+ @retval NULL The path could not be found.
+ @retval NULL There was not enough available memory.
**/
EFI_DEVICE_PATH_PROTOCOL *
EFIAPI
@@ -525,7 +527,9 @@ EfiShellGetDevicePathFromFilePath(
Size = StrSize(Cwd);
Size += StrSize(Path);
NewPath = AllocateZeroPool(Size);
- ASSERT(NewPath != NULL);
+ if (NewPath == NULL) {
+ return (NULL);
+ }
StrCpy(NewPath, Cwd);
if (*Path == L'\\') {
Path++;
@@ -543,8 +547,7 @@ EfiShellGetDevicePathFromFilePath(
//
ASSERT((MapName == NULL && Size == 0) || (MapName != NULL));
MapName = StrnCatGrow(&MapName, &Size, Path, (StrStr(Path, L":")-Path+1));
- if (MapName[StrLen(MapName)-1] != L':') {
- ASSERT(FALSE);
+ if (MapName == NULL || MapName[StrLen(MapName)-1] != L':') {
return (NULL);
}
@@ -564,7 +567,6 @@ EfiShellGetDevicePathFromFilePath(
//
DevicePathCopyForFree = DevicePathCopy = DuplicateDevicePath(DevicePath);
if (DevicePathCopy == NULL) {
- ASSERT(FALSE);
FreePool(MapName);
return (NULL);
}
@@ -1888,6 +1890,9 @@ EfiShellFindFilesInDir(
TempString = NULL;
Size = 0;
TempString = StrnCatGrow(&TempString, &Size, ShellFileHandleGetPath(FileDirHandle), 0);
+ if (TempString == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
TempSpot = StrStr(TempString, L";");
if (TempSpot != NULL) {
@@ -1895,6 +1900,9 @@ EfiShellFindFilesInDir(
}
TempString = StrnCatGrow(&TempString, &Size, BasePath, 0);
+ if (TempString == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
BasePath = TempString;
}
@@ -2239,6 +2247,9 @@ EfiShellFindFiles(
ASSERT(MapName == NULL);
MapName = StrnCatGrow(&MapName, NULL, PatternCopy, Count);
+ if (MapName == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ }
if (!EFI_ERROR(Status)) {
RootDevicePath = EfiShellGetDevicePathFromFilePath(PatternCopy);
@@ -2759,7 +2770,7 @@ EfiShellSetCurDir(
MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);
ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));
MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, DirectoryName, 0);
- if (MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') {
+ if (MapListItem->CurrentDirectoryPath != NULL && MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') {
ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));
MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c
index de2ce2bfc3..ffd05b8ba3 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Bcfg.c
@@ -978,7 +978,7 @@ ShellCommandRunBcfg (
ShellStatus = BcfgAddDebug1(
CurrentOperation.Number1,
CurrentOperation.FileName,
- CurrentOperation.Description,
+ CurrentOperation.Description==NULL?L"":CurrentOperation.Description,
CurrentOperation.Order,
Length / sizeof(CurrentOperation.Order[0]),
CurrentOperation.Target,
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c
index f5fb7d262a..ff3819c6c6 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c
@@ -178,6 +178,7 @@ HFileImageRead (
StatusBarSetStatusString (UnicodeBuffer);
FreePool (UnicodeBuffer);
+ return EFI_OUT_OF_RESOURCES;
}
HFileImageSetFileName (FileName);
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
index 9ab5d89748..945002a2ea 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
@@ -303,6 +303,9 @@ ConvertStringToGuid (
}
TempCopy = NULL;
TempCopy = StrnCatGrow(&TempCopy, NULL, StringGuid, 0);
+ if (TempCopy == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
Walker = TempCopy;
TempSpot = StrStr(Walker, L"-");
if (TempSpot != NULL) {
diff --git a/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c b/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c
index 01f04a5472..ed13dba42f 100644
--- a/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c
+++ b/ShellPkg/Library/UefiShellInstall1CommandsLib/Bcfg.c
@@ -978,7 +978,7 @@ ShellCommandRunBcfgInstall (
ShellStatus = BcfgAddInstall1(
CurrentOperation.Number1,
CurrentOperation.FileName,
- CurrentOperation.Description,
+ CurrentOperation.Description==NULL?L"":CurrentOperation.Description,
CurrentOperation.Order,
Length / sizeof(CurrentOperation.Order[0]),
CurrentOperation.Target,
diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
index 4a85708d0b..121ac50918 100644
--- a/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
+++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
@@ -376,29 +376,33 @@ ShellCommandRunFor (
}
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
}
- //
- // set up for an 'in' for loop
- //
- NewSize = StrSize(ArgSet);
- NewSize += sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]);
- Info = AllocateZeroPool(NewSize);
- ASSERT(Info != NULL);
- Info->Signature = SHELL_FOR_INFO_SIGNATURE;
- CopyMem(Info->Set, ArgSet, StrSize(ArgSet));
- NewSize = StrSize(gEfiShellParametersProtocol->Argv[1]);
- CopyMem(Info->Set+(StrSize(ArgSet)/sizeof(Info->Set[0])), gEfiShellParametersProtocol->Argv[1], NewSize);
- Info->ReplacementName = Info->Set+StrSize(ArgSet)/sizeof(Info->Set[0]);
- Info->CurrentValue = (CHAR16*)Info->Set;
- Info->Step = 0;
- Info->Current = 0;
- Info->End = 0;
-
- if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {
- Info->RemoveSubstAlias = FALSE;
+ if (ArgSet == NULL) {
+ ShellStatus = SHELL_OUT_OF_RESOURCES;
} else {
- Info->RemoveSubstAlias = TRUE;
+ //
+ // set up for an 'in' for loop
+ //
+ NewSize = StrSize(ArgSet);
+ NewSize += sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]);
+ Info = AllocateZeroPool(NewSize);
+ ASSERT(Info != NULL);
+ Info->Signature = SHELL_FOR_INFO_SIGNATURE;
+ CopyMem(Info->Set, ArgSet, StrSize(ArgSet));
+ NewSize = StrSize(gEfiShellParametersProtocol->Argv[1]);
+ CopyMem(Info->Set+(StrSize(ArgSet)/sizeof(Info->Set[0])), gEfiShellParametersProtocol->Argv[1], NewSize);
+ Info->ReplacementName = Info->Set+StrSize(ArgSet)/sizeof(Info->Set[0]);
+ Info->CurrentValue = (CHAR16*)Info->Set;
+ Info->Step = 0;
+ Info->Current = 0;
+ Info->End = 0;
+
+ if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {
+ Info->RemoveSubstAlias = FALSE;
+ } else {
+ Info->RemoveSubstAlias = TRUE;
+ }
+ CurrentScriptFile->CurrentCommand->Data = Info;
}
- CurrentScriptFile->CurrentCommand->Data = Info;
} else if (gUnicodeCollation->StriColl(
gUnicodeCollation,
L"run",
@@ -413,80 +417,61 @@ ShellCommandRunFor (
ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
// ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);
}
- //
- // set up for a 'run' for loop
- //
- Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));
- ASSERT(Info != NULL);
- CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));
- Info->ReplacementName = Info->Set;
- Info->CurrentValue = NULL;
- ArgSetWalker = ArgSet;
- if (ArgSetWalker[0] != L'(') {
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
- gShellLevel1HiiHandle,
- ArgSet,
- CurrentScriptFile!=NULL
- && CurrentScriptFile->CurrentCommand!=NULL
- ? CurrentScriptFile->CurrentCommand->Line:0);
- ShellStatus = SHELL_INVALID_PARAMETER;
+ if (ArgSet == NULL) {
+ ShellStatus = SHELL_OUT_OF_RESOURCES;
} else {
- TempSpot = StrStr(ArgSetWalker, L")");
- if (TempSpot != NULL) {
- TempString = TempSpot+1;
- if (*(TempString) != CHAR_NULL) {
- while(TempString != NULL && *TempString == L' ') {
- TempString++;
- }
- if (StrLen(TempString) > 0) {
- TempSpot = NULL;
- }
- }
- }
- if (TempSpot == NULL) {
+ //
+ // set up for a 'run' for loop
+ //
+ Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));
+ ASSERT(Info != NULL);
+ CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));
+ Info->ReplacementName = Info->Set;
+ Info->CurrentValue = NULL;
+ ArgSetWalker = ArgSet;
+ if (ArgSetWalker[0] != L'(') {
ShellPrintHiiEx(
-1,
-1,
NULL,
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
gShellLevel1HiiHandle,
+ ArgSet,
CurrentScriptFile!=NULL
&& CurrentScriptFile->CurrentCommand!=NULL
? CurrentScriptFile->CurrentCommand->Line:0);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- *TempSpot = CHAR_NULL;
- ArgSetWalker++;
- while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
- ArgSetWalker++;
+ TempSpot = StrStr(ArgSetWalker, L")");
+ if (TempSpot != NULL) {
+ TempString = TempSpot+1;
+ if (*(TempString) != CHAR_NULL) {
+ while(TempString != NULL && *TempString == L' ') {
+ TempString++;
+ }
+ if (StrLen(TempString) > 0) {
+ TempSpot = NULL;
+ }
+ }
}
- if (!ShellIsValidForNumber(ArgSetWalker)) {
+ if (TempSpot == NULL) {
ShellPrintHiiEx(
-1,
-1,
NULL,
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
gShellLevel1HiiHandle,
- ArgSet,
CurrentScriptFile!=NULL
&& CurrentScriptFile->CurrentCommand!=NULL
? CurrentScriptFile->CurrentCommand->Line:0);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- if (ArgSetWalker[0] == L'-') {
- Info->Current = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
- } else {
- Info->Current = (INTN)ShellStrToUintn(ArgSetWalker);
- }
- ArgSetWalker = StrStr(ArgSetWalker, L" ");
+ *TempSpot = CHAR_NULL;
+ ArgSetWalker++;
while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
ArgSetWalker++;
}
- if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){
+ if (!ShellIsValidForNumber(ArgSetWalker)) {
ShellPrintHiiEx(
-1,
-1,
@@ -500,73 +485,96 @@ ShellCommandRunFor (
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
if (ArgSetWalker[0] == L'-') {
- Info->End = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
- } else {
- Info->End = (INTN)ShellStrToUintn(ArgSetWalker);
- }
- if (Info->Current < Info->End) {
- Info->Step = 1;
+ Info->Current = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
} else {
- Info->Step = -1;
+ Info->Current = (INTN)ShellStrToUintn(ArgSetWalker);
}
-
ArgSetWalker = StrStr(ArgSetWalker, L" ");
while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
ArgSetWalker++;
}
- if (ArgSetWalker != NULL && *ArgSetWalker != CHAR_NULL) {
- if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
- gShellLevel1HiiHandle,
- ArgSet,
- CurrentScriptFile!=NULL
- && CurrentScriptFile->CurrentCommand!=NULL
- ? CurrentScriptFile->CurrentCommand->Line:0);
- ShellStatus = SHELL_INVALID_PARAMETER;
+ if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
+ gShellLevel1HiiHandle,
+ ArgSet,
+ CurrentScriptFile!=NULL
+ && CurrentScriptFile->CurrentCommand!=NULL
+ ? CurrentScriptFile->CurrentCommand->Line:0);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ if (ArgSetWalker[0] == L'-') {
+ Info->End = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
} else {
- if (*ArgSetWalker == L')') {
- ASSERT(Info->Step == 1 || Info->Step == -1);
+ Info->End = (INTN)ShellStrToUintn(ArgSetWalker);
+ }
+ if (Info->Current < Info->End) {
+ Info->Step = 1;
+ } else {
+ Info->Step = -1;
+ }
+
+ ArgSetWalker = StrStr(ArgSetWalker, L" ");
+ while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
+ ArgSetWalker++;
+ }
+ if (ArgSetWalker != NULL && *ArgSetWalker != CHAR_NULL) {
+ if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
+ gShellLevel1HiiHandle,
+ ArgSet,
+ CurrentScriptFile!=NULL
+ && CurrentScriptFile->CurrentCommand!=NULL
+ ? CurrentScriptFile->CurrentCommand->Line:0);
+ ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- if (ArgSetWalker[0] == L'-') {
- Info->Step = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
+ if (*ArgSetWalker == L')') {
+ ASSERT(Info->Step == 1 || Info->Step == -1);
} else {
- Info->Step = (INTN)ShellStrToUintn(ArgSetWalker);
- }
-
- if (StrStr(ArgSetWalker, L" ") != NULL) {
- ShellPrintHiiEx(
- -1,
- -1,
- NULL,
- STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
- gShellLevel1HiiHandle,
- ArgSet,
- CurrentScriptFile!=NULL
- && CurrentScriptFile->CurrentCommand!=NULL
- ? CurrentScriptFile->CurrentCommand->Line:0);
- ShellStatus = SHELL_INVALID_PARAMETER;
+ if (ArgSetWalker[0] == L'-') {
+ Info->Step = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);
+ } else {
+ Info->Step = (INTN)ShellStrToUintn(ArgSetWalker);
+ }
+
+ if (StrStr(ArgSetWalker, L" ") != NULL) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
+ gShellLevel1HiiHandle,
+ ArgSet,
+ CurrentScriptFile!=NULL
+ && CurrentScriptFile->CurrentCommand!=NULL
+ ? CurrentScriptFile->CurrentCommand->Line:0);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
}
}
+
}
-
}
}
}
}
- }
- if (ShellStatus == SHELL_SUCCESS) {
- if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {
- Info->RemoveSubstAlias = FALSE;
- } else {
- Info->RemoveSubstAlias = TRUE;
+ if (ShellStatus == SHELL_SUCCESS) {
+ if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {
+ Info->RemoveSubstAlias = FALSE;
+ } else {
+ Info->RemoveSubstAlias = TRUE;
+ }
+ }
+ if (CurrentScriptFile->CurrentCommand != NULL) {
+ CurrentScriptFile->CurrentCommand->Data = Info;
}
- }
- if (CurrentScriptFile->CurrentCommand != NULL) {
- CurrentScriptFile->CurrentCommand->Data = Info;
}
} else {
ShellPrintHiiEx(
@@ -665,27 +673,30 @@ ShellCommandRunFor (
//
ASSERT(TempString == NULL);
TempString = StrnCatGrow(&TempString, NULL, Info->CurrentValue, 0);
- TempSpot = StrStr(TempString, L"\" \"");
- if (TempSpot != NULL) {
- *TempSpot = CHAR_NULL;
- }
- while (TempString[StrLen(TempString)-1] == L'\"') {
- TempString[StrLen(TempString)-1] = CHAR_NULL;
- }
- InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);
- Info->CurrentValue += StrLen(TempString);
+ if (TempString == NULL) {
+ ShellStatus = SHELL_OUT_OF_RESOURCES;
+ } else {
+ TempSpot = StrStr(TempString, L"\" \"");
+ if (TempSpot != NULL) {
+ *TempSpot = CHAR_NULL;
+ }
+ while (TempString[StrLen(TempString)-1] == L'\"') {
+ TempString[StrLen(TempString)-1] = CHAR_NULL;
+ }
+ InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);
+ Info->CurrentValue += StrLen(TempString);
- if (Info->CurrentValue[0] == L'\"') {
- Info->CurrentValue++;
- }
- while (Info->CurrentValue[0] == L' ') {
- Info->CurrentValue++;
- }
- if (Info->CurrentValue[0] == L'\"') {
- Info->CurrentValue++;
+ if (Info->CurrentValue[0] == L'\"') {
+ Info->CurrentValue++;
+ }
+ while (Info->CurrentValue[0] == L' ') {
+ Info->CurrentValue++;
+ }
+ if (Info->CurrentValue[0] == L'\"') {
+ Info->CurrentValue++;
+ }
+ FreePool(TempString);
}
- FreePool(TempString);
-
} else {
CurrentScriptFile->CurrentCommand->Data = NULL;
//
diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c
index d305306124..08927319d3 100644
--- a/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c
+++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c
@@ -739,6 +739,9 @@ MoveToTagSpecial (
//
CommandName = NULL;
CommandName = StrnCatGrow(&CommandName, NULL, CommandNode->Cl, 0);
+ if (CommandName == NULL) {
+ continue;
+ }
CommandWalker = CommandName;
while (CommandWalker[0] == L' ') {
CommandWalker++;
diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c
index a9dd6ccdab..6f67f49aea 100644
--- a/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c
+++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c
@@ -145,6 +145,10 @@ TestNodeForMove (
//
CommandName = NULL;
CommandName = StrnCatGrow(&CommandName, NULL, CommandNode->Cl, 0);
+ if (CommandName == NULL) {
+ return (FALSE);
+ }
+
CommandNameWalker = CommandName;
while(CommandNameWalker[0] == L' ') {
CommandNameWalker++;
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c
index 358f63d8db..a1f9448df9 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c
@@ -414,6 +414,9 @@ PerformSingleMappingDisplay(
CurrentName = NULL;
CurrentName = StrnCatGrow(&CurrentName, 0, MapList, 0);
+ if (CurrentName == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
TempSpot = StrStr(CurrentName, L";");
if (TempSpot != NULL) {
*TempSpot = CHAR_NULL;
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
index aa40bbf22f..f2f2e60b7c 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
@@ -642,10 +642,15 @@ CheckAndSetTimeZone (
}
Status = gRT->GetTime(&TheTime, NULL);
- ASSERT_EFI_ERROR(Status);
+ if (EFI_ERROR(Status)) {
+ return (SHELL_DEVICE_ERROR);
+ }
TimeZoneCopy = NULL;
TimeZoneCopy = StrnCatGrow(&TimeZoneCopy, NULL, TimeZoneString, 0);
+ if (TimeZoneCopy == NULL) {
+ return (SHELL_OUT_OF_RESOURCES);
+ }
Walker = TimeZoneCopy;
Walker2 = StrStr(Walker, L":");
if (Walker2 != NULL && *Walker2 == L':') {
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
index 6bdc39f08b..b153d2fe45 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
@@ -226,6 +226,10 @@ VerifyIntermediateDirectories (
PathCopy = StrnCatGrow(&PathCopy, NULL, Path, 0);
FileHandle = NULL;
+ if (PathCopy == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
+
for (TempSpot = &PathCopy[StrLen(PathCopy)-1] ; *TempSpot != CHAR_NULL && *TempSpot != L'\\' ; TempSpot = &PathCopy[StrLen(PathCopy)-1]){
*TempSpot = CHAR_NULL;
}
diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c b/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c
index 7eb3c8c0e8..29f6be3931 100644
--- a/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c
+++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c
@@ -79,11 +79,16 @@ DoTouchByHandle (
if (FS == NULL) {
FS = StrnCatGrow(&FS, NULL, Name, 0);
- TempSpot = StrStr(FS, L"\\");
- if (TempSpot != NULL) {
- *TempSpot = CHAR_NULL;
+ if (FS != NULL) {
+ TempSpot = StrStr(FS, L"\\");
+ if (TempSpot != NULL) {
+ *TempSpot = CHAR_NULL;
+ }
}
}
+ if (FS == NULL) {
+ return (EFI_INVALID_PARAMETER);
+ }
//
// do it