diff options
author | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-10-14 19:21:13 +0000 |
---|---|---|
committer | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-10-14 19:21:13 +0000 |
commit | 532691c8ba90e5022174503ab0781322c6f79cab (patch) | |
tree | 7c598451898c979b99cdfa0ec1573d509d5ee1ff /ShellPkg/Application/Shell/Shell.c | |
parent | de2a15eebbf467c335f3e28ff0ba0ca6dd0ddcf2 (diff) | |
download | edk2-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/Application/Shell/Shell.c')
-rw-r--r-- | ShellPkg/Application/Shell/Shell.c | 29 |
1 files changed, 21 insertions, 8 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;
}
|