]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/Common/BasePeCoff.c
BaseTools/C/Common: Avoid possible NULL pointer dereference
[mirror_edk2.git] / BaseTools / Source / C / Common / BasePeCoff.c
index d0cc1af246302c3af493d4de7d61a886ccdff685..9adbdfaf09da202c25a939ec914ac45cccb6de18 100644 (file)
@@ -650,6 +650,10 @@ Returns:
                         ImageContext,\r
                         RelocDir->VirtualAddress + RelocDir->Size - 1\r
                         );\r
+        if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd < RelocBase) {\r
+          ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
+          return RETURN_LOAD_ERROR;\r
+        }\r
       } else {\r
         //\r
         // Set base and end to bypass processing below.\r
@@ -674,6 +678,10 @@ Returns:
                         ImageContext,\r
                         RelocDir->VirtualAddress + RelocDir->Size - 1\r
                         );\r
+        if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd < RelocBase) {\r
+          ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
+          return RETURN_LOAD_ERROR;\r
+        }\r
       } else {\r
         //\r
         // Set base and end to bypass processing below.\r
@@ -710,6 +718,10 @@ Returns:
     RelocEnd  = (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock);\r
     if (!(ImageContext->IsTeImage)) {\r
       FixupBase = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress);\r
+      if (FixupBase == NULL) {\r
+        ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
+        return RETURN_LOAD_ERROR;\r
+      }\r
     } else {\r
       FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress +\r
                     RelocBase->VirtualAddress +\r