summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2011-10-17 17:49:21 +0000
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2011-10-17 17:49:21 +0000
commitc8c2259156709f1995994dadbf469a8920649bc8 (patch)
tree580e9b8baf71c878fe185452451c7685023568c9
parent532691c8ba90e5022174503ab0781322c6f79cab (diff)
downloadedk2-platforms-c8c2259156709f1995994dadbf469a8920649bc8.tar.xz
ShellPkg: Add checking for memory allocation and pointer returns from functions.
signed-off-by: jcarsey reviewed-by: lgrosenb git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12542 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--ShellPkg/Application/Shell/ShellParametersProtocol.c2
-rw-r--r--ShellPkg/Application/Shell/ShellProtocol.c4
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c8
-rw-r--r--ShellPkg/Library/UefiShellLib/UefiShellLib.c11
4 files changed, 16 insertions, 9 deletions
diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c
index 55cf3c279e..91a0f5f8a2 100644
--- a/ShellPkg/Application/Shell/ShellParametersProtocol.c
+++ b/ShellPkg/Application/Shell/ShellParametersProtocol.c
@@ -1040,7 +1040,7 @@ UpdateStdInStdOutStdErr(
TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
}
Size = 0;
- if (((EFI_FILE_PROTOCOL*)TempHandle)->Read(TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL) {
+ if (TempHandle != NULL || ((EFI_FILE_PROTOCOL*)TempHandle)->Read(TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL) {
Status = EFI_INVALID_PARAMETER;
} else {
ShellParameters->StdIn = TempHandle;
diff --git a/ShellPkg/Application/Shell/ShellProtocol.c b/ShellPkg/Application/Shell/ShellProtocol.c
index 6b81918101..00bbc358fa 100644
--- a/ShellPkg/Application/Shell/ShellProtocol.c
+++ b/ShellPkg/Application/Shell/ShellProtocol.c
@@ -2249,9 +2249,7 @@ EfiShellFindFiles(
MapName = StrnCatGrow(&MapName, NULL, PatternCopy, Count);
if (MapName == NULL) {
Status = EFI_OUT_OF_RESOURCES;
- }
-
- if (!EFI_ERROR(Status)) {
+ } else {
RootDevicePath = EfiShellGetDevicePathFromFilePath(PatternCopy);
if (RootDevicePath == NULL) {
Status = EFI_INVALID_PARAMETER;
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
index b153d2fe45..69193d5efa 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
@@ -163,8 +163,8 @@ ShellLevel2CommandsLibDestructor (
@param[in] Path The unknown Path Value
@retval NULL A memory allocation failed
- @retval NULL a fully qualified path could not be discovered.
- @retval other pointer to a fuly qualified path.
+ @retval NULL A fully qualified path could not be discovered.
+ @retval other An allocated pointer to a fuly qualified path.
**/
CHAR16*
EFIAPI
@@ -194,6 +194,10 @@ GetFullyQualifiedPath(
PathCleanUpDirectories(PathToReturn);
+ if (PathTpReturn == NULL) {
+ return NULL;
+ }
+
while (PathToReturn[StrLen(PathToReturn)-1] == L'*') {
PathToReturn[StrLen(PathToReturn)-1] = CHAR_NULL;
}
diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
index 508e9e0ec0..d131f9b189 100644
--- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c
+++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c
@@ -2865,9 +2865,10 @@ ShellPrintHiiEx(
@param[in] DirName Path to directory to test.
- @retval EFI_SUCCESS The Path represents a directory
- @retval EFI_NOT_FOUND The Path does not represent a directory
- @return other The path failed to open
+ @retval EFI_SUCCESS The Path represents a directory
+ @retval EFI_NOT_FOUND The Path does not represent a directory
+ @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
+ @return The path failed to open
**/
EFI_STATUS
EFIAPI
@@ -2892,6 +2893,10 @@ ShellIsDirectory(
//
if (gEfiShellProtocol != NULL) {
TempLocation = StrnCatGrow(&TempLocation, NULL, DirName, 0);
+ if (TempLocation == NULL) {
+ ShellCloseFile(&Handle);
+ return (EFI_OUT_OF_RESOURCES);
+ }
TempLocation2 = StrStr(TempLocation, L":");
if (TempLocation2 != NULL && StrLen(StrStr(TempLocation, L":")) == 2) {
*(TempLocation2+1) = CHAR_NULL;