]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c
ShellPkg: Add checks for NULL pointers.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Compress.c
index 01321d1ed674d7451750afb0c0e1d3ceccc49085..b1f8327f4ab01ae7276a0d4a8ed3eefc18f78a41 100644 (file)
@@ -607,8 +607,10 @@ FreadCrc (
   Advance the current position (read in new data if needed).\r
   Delete outdated string info. Find a match string for current position.\r
 \r
+  @retval TRUE      The operation was successful.\r
+  @retval FALSE     The operation failed due to insufficient memory.\r
 **/\r
-VOID\r
+BOOLEAN\r
 EFIAPI\r
 GetNextMatch (\r
   VOID\r
@@ -621,6 +623,9 @@ GetNextMatch (
   mPos++;\r
   if (mPos == WNDSIZ * 2) {\r
     Temp = AllocateZeroPool (WNDSIZ + MAXMATCH);\r
+    if (Temp == NULL) {\r
+      return (FALSE);\r
+    }\r
     CopyMem (Temp, &mText[WNDSIZ], WNDSIZ + MAXMATCH);\r
     CopyMem (&mText[0], Temp, WNDSIZ + MAXMATCH);\r
     FreePool (Temp);\r
@@ -631,6 +636,8 @@ GetNextMatch (
 \r
   DeleteNode ();\r
   InsertNode ();\r
+\r
+  return (TRUE);\r
 }\r
 \r
 /**\r
@@ -1286,7 +1293,9 @@ Encode (
   while (mRemainder > 0) {\r
     LastMatchLen  = mMatchLen;\r
     LastMatchPos  = mMatchPos;\r
-    GetNextMatch ();\r
+    if (!GetNextMatch ()) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+    }\r
     if (mMatchLen > mRemainder) {\r
       mMatchLen = mRemainder;\r
     }\r
@@ -1306,7 +1315,9 @@ Encode (
              (mPos - LastMatchPos - 2) & (WNDSIZ - 1));\r
       LastMatchLen--;\r
       while (LastMatchLen > 0) {\r
-        GetNextMatch ();\r
+        if (!GetNextMatch ()) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+        }\r
         LastMatchLen--;\r
       }\r
 \r
@@ -1318,16 +1329,16 @@ Encode (
 \r
   HufEncodeEnd ();\r
   FreeMemory ();\r
-  return EFI_SUCCESS;\r
+  return (Status);\r
 }\r
 \r
 /**\r
   The compression routine.\r
 \r
-  @param[in]      SrcBuffer     The buffer containing the source data.\r
-  @param[in]      SrcSize       The number of bytes in SrcBuffer.\r
-  @param[in]      DstBuffer     The buffer to put the compressed image in.\r
-  @param[in,out]  DstSize       On input the size (in bytes) of DstBuffer, on\r
+  @param[in]       SrcBuffer     The buffer containing the source data.\r
+  @param[in]       SrcSize       The number of bytes in SrcBuffer.\r
+  @param[in]       DstBuffer     The buffer to put the compressed image in.\r
+  @param[in, out]  DstSize       On input the size (in bytes) of DstBuffer, on\r
                                 return the number of bytes placed in DstBuffer.\r
 \r
   @retval EFI_SUCCESS           The compression was sucessful.\r