summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Flick <dougflick@microsoft.com>2024-08-14 12:46:16 -0700
committerDoug Flick <dougflick@microsoft.com>2024-09-27 10:56:35 -0700
commit6c2291732a5b1a1186c7b405e6c688983915acd2 (patch)
tree621a7338c0166c565c08aaf60fe5bdfb4508aeb1
parent8b295e0aad55cdf0c20eba6398862832ce188a0c (diff)
downloadedk2-6c2291732a5b1a1186c7b405e6c688983915acd2.tar.gz
MdePkg: Fix overflow issue in BasePeCoffLib: PeCoffLoaderRelocateImageadvisory-fix-1
The RelocDir->Size is a UINT32 value, and RelocDir->VirtualAddress is also a UINT32 value. The current code does not check for overflow when adding RelocDir->Size to RelocDir->VirtualAddress. This patch adds a check to ensure that the addition does not overflow. Signed-off-by: Doug Flick <dougflick@microsoft.com> Authored-by: sriraamx gobichettipalayam <sriraamx.gobichettipalayam.raghupathi@intel.com>
-rw-r--r--MdePkg/Library/BasePeCoffLib/BasePeCoff.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
index 86ff2e769b..128090d98e 100644
--- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
+++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c
@@ -1054,7 +1054,7 @@ PeCoffLoaderRelocateImage (
RelocDir = &Hdr.Te->DataDirectory[0];
}
- if ((RelocDir != NULL) && (RelocDir->Size > 0)) {
+ if ((RelocDir != NULL) && (RelocDir->Size > 0) && (RelocDir->Size - 1 < MAX_UINT32 - RelocDir->VirtualAddress)) {
RelocBase = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress, TeStrippedOffset);
RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (
ImageContext,