]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellManParser.c
ShellPkg: Add checking for memory allocation and pointer returns from functions.
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellManParser.c
index ab32c36b7502816a31db79b2da770366f434a60d..470f51a8ea3d2d45202c35a854561e7daaa8800a 100644 (file)
@@ -180,6 +180,10 @@ ManBufferFindSections(
         TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));\r
         ASSERT(TempString == NULL);\r
         TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);\r
+        if (TempString == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          break;\r
+        }\r
         SectionName = TempString;\r
         SectionLen = StrLen(SectionName);\r
         SectionName = StrStr(Sections, SectionName);\r
@@ -197,12 +201,24 @@ ManBufferFindSections(
         TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));\r
         ASSERT(TempString == NULL);\r
         TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);\r
+        if (TempString == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          break;\r
+        }\r
         //\r
         // copy and save the current line.\r
         //\r
         ASSERT((*HelpText == NULL && *HelpSize == 0) || (*HelpText != NULL));\r
         StrnCatGrow (HelpText, HelpSize, TempString, 0);\r
+        if (HelpText == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          break;\r
+        }\r
         StrnCatGrow (HelpText, HelpSize, L"\r\n", 0);\r
+        if (HelpText == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          break;\r
+        }\r
       }\r
     }\r
     SHELL_FREE_NON_NULL(TempString);\r
@@ -423,12 +439,12 @@ ManBufferFindTitleSection(
 \r
   Upon a sucessful return the caller is responsible to free the memory in *BriefDesc\r
 \r
-  @param[in] Handle             FileHandle to read from\r
-  @param[in] Command            name of command's section to find\r
-  @param[out] BriefDesc         pointer to pointer to string where description goes.\r
-  @param[out] BriefSize         pointer to size of allocated BriefDesc\r
-  @param[in,out] Ascii          TRUE if the file is ASCII, FALSE otherwise, will be\r
-                                set if the file handle is at the 0 position.\r
+  @param[in] Handle              FileHandle to read from\r
+  @param[in] Command             name of command's section to find\r
+  @param[out] BriefDesc          pointer to pointer to string where description goes.\r
+  @param[out] BriefSize          pointer to size of allocated BriefDesc\r
+  @param[in, out] Ascii          TRUE if the file is ASCII, FALSE otherwise, will be\r
+                                 set if the file handle is at the 0 position.\r
 \r
   @retval EFI_OUT_OF_RESOURCES  a memory allocation failed.\r
   @retval EFI_SUCCESS           the section was found and its description sotred in\r
@@ -548,7 +564,8 @@ ManFileFindTitleSection(
   @retval EFI_SUCCESS           The help text was returned.\r
   @retval EFI_OUT_OF_RESOURCES  The necessary buffer could not be allocated to hold the\r
                                 returned help text.\r
-  @retval EFI_INVALID_PARAMETER HelpText is NULL\r
+  @retval EFI_INVALID_PARAMETER HelpText is NULL.\r
+  @retval EFI_INVALID_PARAMETER ManFileName is invalid.\r
   @retval EFI_NOT_FOUND         There is no help text available for Command.\r
 **/\r
 EFI_STATUS\r
@@ -594,6 +611,9 @@ ProcessManFile(
   } else {\r
     FileHandle    = NULL;\r
     TempString  = GetManFileName(ManFileName);\r
+    if (TempString == NULL) {\r
+      return (EFI_INVALID_PARAMETER);\r
+    }\r
 \r
     Status = SearchPathForFile(TempString, &FileHandle);\r
     if (EFI_ERROR(Status)) {\r