]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/Common/FvLib.c
BaseTools: Add more checker in Decompress algorithm to access the valid buffer (CVE...
[mirror_edk2.git] / BaseTools / Source / C / Common / FvLib.c
index 4758749dc363d9885613120f2f4fc4c2b31d4bcb..b5ae45de0927e02be009359111eaa5ed1b2eb6ea 100644 (file)
@@ -1,21 +1,14 @@
 /** @file\r
+These functions assist in parsing and manipulating a Firmware Volume.\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials                          \r
-are licensed and made available under the terms and conditions of the BSD License         \r
-which accompanies this distribution.  The full text of the license may be found at        \r
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
 \r
-Module Name:\r
-\r
-  FvLib.c\r
-\r
-Abstract:\r
-\r
-  These functions assist in parsing and manipulating a Firmware Volume.\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
@@ -51,9 +44,9 @@ Arguments:
 \r
   Fv            Buffer containing the FV.\r
   FvLength      Length of the FV\r
-    \r
+\r
 Returns:\r
\r
+\r
   EFI_SUCCESS             Function Completed successfully.\r
   EFI_INVALID_PARAMETER   A required parameter was NULL.\r
 \r
@@ -87,9 +80,9 @@ Arguments:
 \r
   FvHeader      Pointer to the FV buffer.\r
   FvLength      Length of the FV\r
-    \r
+\r
 Returns:\r
\r
+\r
   EFI_SUCCESS             Function Completed successfully.\r
   EFI_INVALID_PARAMETER   A required parameter was NULL.\r
   EFI_ABORTED             The library needs to be initialized.\r
@@ -124,16 +117,16 @@ GetNextFile (
 Routine Description:\r
 \r
   This function returns the next file.  If the current file is NULL, it returns\r
-  the first file in the FV.  If the function returns EFI_SUCCESS and the file \r
+  the first file in the FV.  If the function returns EFI_SUCCESS and the file\r
   pointer is NULL, then there are no more files in the FV.\r
 \r
 Arguments:\r
 \r
   CurrentFile   Pointer to the current file, must be within the current FV.\r
   NextFile      Pointer to the next file in the FV.\r
-    \r
+\r
 Returns:\r
\r
+\r
   EFI_SUCCESS             Function completed successfully.\r
   EFI_INVALID_PARAMETER   A required parameter was NULL or is out of range.\r
   EFI_ABORTED             The library needs to be initialized.\r
@@ -201,7 +194,7 @@ Returns:
   //\r
   // Get next file, compensate for 8 byte alignment if necessary.\r
   //\r
-  *NextFile = (EFI_FFS_FILE_HEADER *) ((((UINTN) CurrentFile - (UINTN) mFvHeader + GetFfsFileLength(CurrentFile) + 0x07) & (-1 << 3)) + (UINT8 *) mFvHeader);\r
+  *NextFile = (EFI_FFS_FILE_HEADER *) ((((UINTN) CurrentFile - (UINTN) mFvHeader + GetFfsFileLength(CurrentFile) + 0x07) & (~(UINTN) 7)) + (UINT8 *) mFvHeader);\r
 \r
   //\r
   // Verify file is in this FV.\r
@@ -486,7 +479,7 @@ Returns:
     //\r
     // Find next section (including compensating for alignment issues.\r
     //\r
-    CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((((UINTN) CurrentSection.CommonHeader) + GetSectionFileLength(CurrentSection.CommonHeader) + 0x03) & (-1 << 2));\r
+    CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((((UINTN) CurrentSection.CommonHeader) + GetSectionFileLength(CurrentSection.CommonHeader) + 0x03) & (~(UINTN) 3));\r
   }\r
 \r
   return EFI_NOT_FOUND;\r
@@ -503,7 +496,7 @@ GetSectionByType (
 \r
 Routine Description:\r
 \r
-  Find a section in a file by type and instance.  An instance of 1 is the first \r
+  Find a section in a file by type and instance.  An instance of 1 is the first\r
   instance.  The function will return NULL if a matching section cannot be found.\r
   GUID-defined sections, if special processing is not needed, are handled in a\r
   depth-first manner.\r
@@ -550,7 +543,7 @@ Returns:
   // Get the first section\r
   //\r
   CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((UINTN) File + GetFfsHeaderLength(File));\r
-  \r
+\r
   //\r
   // Depth-first manner to find section file.\r
   //\r
@@ -791,7 +784,7 @@ Returns:
     return 0;\r
   }\r
   if (FfsHeader->Attributes & FFS_ATTRIB_LARGE_FILE) {\r
-    return ((EFI_FFS_FILE_HEADER2 *)FfsHeader)->ExtendedSize;\r
+    return (UINT32) ((EFI_FFS_FILE_HEADER2 *)FfsHeader)->ExtendedSize;\r
   } else {\r
     return GetLength(FfsHeader->Size);\r
   }\r
@@ -865,7 +858,7 @@ Returns:
   EFI_SUCCESS              The function completed successfully.\r
   EFI_INVALID_PARAMETER    One of the input parameters was invalid.\r
   EFI_ABORTED              Operation aborted.\r
-  \r
+\r
 --*/\r
 {\r
   EFI_STATUS  Status;\r
@@ -912,7 +905,7 @@ Routine Description:
   It in no way validate the FFS file.\r
 \r
 Arguments:\r
-  \r
+\r
   ErasePolarity The erase polarity for the file state bits.\r
   FfsHeader     Pointer to a FFS file.\r
 \r