From 6d772a4b8e4c2d71d628fd5203a1fb102c87b1b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Ha=CC=88user?= <8659494+mhaeuser@users.noreply.github.com> Date: Thu, 27 Apr 2023 17:32:35 +0200 Subject: [PATCH] MdePkg/BasePeCoffLib2: Fix uninitialized RtContext for RelocateImage() --- MdePkg/Library/BasePeCoffLib2/PeCoffRelocate.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MdePkg/Library/BasePeCoffLib2/PeCoffRelocate.c b/MdePkg/Library/BasePeCoffLib2/PeCoffRelocate.c index 39a2b26dff..8c91496e28 100644 --- a/MdePkg/Library/BasePeCoffLib2/PeCoffRelocate.c +++ b/MdePkg/Library/BasePeCoffLib2/PeCoffRelocate.c @@ -438,6 +438,13 @@ PeCoffRelocateImage ( ASSERT (RuntimeContext != NULL || RuntimeContextSize == 0); ASSERT (RuntimeContext == NULL || RuntimeContextSize >= sizeof (PE_COFF_LOADER_RUNTIME_CONTEXT) + Context->RelocDirSize * (sizeof (UINT64) / sizeof (UINT16))); // + // Initialise the Image runtime context header. + // + if (RuntimeContext != NULL) { + RuntimeContext->RelocDirRva = Context->RelocDirRva; + RuntimeContext->RelocDirSize = Context->RelocDirSize; + } + // // Verify the Relocation Directory is not empty. // if (Context->RelocDirSize == 0) { @@ -458,13 +465,6 @@ PeCoffRelocateImage ( if (RuntimeContext == NULL && Adjust == 0) { return RETURN_SUCCESS; } - // - // Initialise the Image runtime context header. - // - if (RuntimeContext != NULL) { - RuntimeContext->RelocDirRva = Context->RelocDirRva; - RuntimeContext->RelocDirSize = Context->RelocDirSize; - } RelocBlockOffset = Context->RelocDirRva; TopOfRelocDir = Context->RelocDirRva + Context->RelocDirSize;