]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellProtocol.c
ShellPkg: Add checking for memory allocation and pointer returns from functions.
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellProtocol.c
index de7dc3cad91b08b28be628969f3a69883c2e86c3..6b81918101b221f7e3790a1a3dda1c8c076e8454 100644 (file)
@@ -488,10 +488,12 @@ EfiShellGetFilePathFromDevicePath(
   This function converts a file system style name to a device path, by replacing any\r
   mapping references to the associated device path.\r
 \r
-  @param Path                   the pointer to the path\r
+  @param[in] Path               The pointer to the path.\r
 \r
-  @return all                   The pointer of the file path. The file path is callee\r
+  @return                       The pointer of the file path. The file path is callee\r
                                 allocated and should be freed by the caller.\r
+  @retval NULL                  The path could not be found.\r
+  @retval NULL                  There was not enough available memory.\r
 **/\r
 EFI_DEVICE_PATH_PROTOCOL *\r
 EFIAPI\r
@@ -525,7 +527,9 @@ EfiShellGetDevicePathFromFilePath(
     Size = StrSize(Cwd);\r
     Size += StrSize(Path);\r
     NewPath = AllocateZeroPool(Size);\r
-    ASSERT(NewPath != NULL);\r
+    if (NewPath == NULL) {\r
+      return (NULL);\r
+    }\r
     StrCpy(NewPath, Cwd);\r
     if (*Path == L'\\') {\r
       Path++;\r
@@ -543,8 +547,7 @@ EfiShellGetDevicePathFromFilePath(
   //\r
   ASSERT((MapName == NULL && Size == 0) || (MapName != NULL));\r
   MapName = StrnCatGrow(&MapName, &Size, Path, (StrStr(Path, L":")-Path+1));\r
-  if (MapName[StrLen(MapName)-1] != L':') {\r
-    ASSERT(FALSE);\r
+  if (MapName == NULL || MapName[StrLen(MapName)-1] != L':') {\r
     return (NULL);\r
   }\r
 \r
@@ -564,7 +567,6 @@ EfiShellGetDevicePathFromFilePath(
   //\r
   DevicePathCopyForFree = DevicePathCopy = DuplicateDevicePath(DevicePath);\r
   if (DevicePathCopy == NULL) {\r
-    ASSERT(FALSE);\r
     FreePool(MapName);\r
     return (NULL);\r
   }\r
@@ -1888,6 +1890,9 @@ EfiShellFindFilesInDir(
     TempString        = NULL;\r
     Size              = 0;\r
     TempString        = StrnCatGrow(&TempString, &Size, ShellFileHandleGetPath(FileDirHandle), 0);\r
+    if (TempString == NULL) {\r
+      return (EFI_OUT_OF_RESOURCES);\r
+    }\r
     TempSpot          = StrStr(TempString, L";");\r
 \r
     if (TempSpot != NULL) {\r
@@ -1895,6 +1900,9 @@ EfiShellFindFilesInDir(
     }\r
 \r
     TempString        = StrnCatGrow(&TempString, &Size, BasePath, 0);\r
+    if (TempString == NULL) {\r
+      return (EFI_OUT_OF_RESOURCES);\r
+    }\r
     BasePath          = TempString;\r
   }\r
 \r
@@ -2239,6 +2247,9 @@ EfiShellFindFiles(
 \r
   ASSERT(MapName == NULL);\r
   MapName = StrnCatGrow(&MapName, NULL, PatternCopy, Count);\r
+  if (MapName == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+  }\r
 \r
   if (!EFI_ERROR(Status)) {\r
     RootDevicePath = EfiShellGetDevicePathFromFilePath(PatternCopy);\r
@@ -2759,7 +2770,7 @@ EfiShellSetCurDir(
       MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);\r
       ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r
       MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, DirectoryName, 0);\r
-      if (MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') {\r
+      if (MapListItem->CurrentDirectoryPath != NULL && MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') {\r
         ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r
         MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);\r
       }\r