summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMingjie Shen <shen497@purdue.edu>2026-08-31 18:14:24 -0400
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2026-09-03 10:36:41 +0000
commit52f19aacd569aa0f1f264108ed518a96657f9088 (patch)
treed0dd59a9aae0be99dc2934ea99c5e693b18cc1d0
parentd68e8b775ffd142aa93648b4d45255d3a8233874 (diff)
downloadedk2-52f19aacd569aa0f1f264108ed518a96657f9088.tar.gz
edk2-52f19aacd569aa0f1f264108ed518a96657f9088.zip
BaseTools/GenSec: Use SECTION_SIZE to read section size
Replace the open-coded read of the 3-byte section Size[] field with the SECTION_SIZE() macro from Pi/PiFirmwareFile.h. The macro reads exactly the three Size[] bytes (endianness-safe) instead of a 4-byte load that over-reads the adjacent byte. No functional change. Verified by building BaseTools and running GenSec: python3 BaseTools/Edk2ToolsBuild.py -t GCC GenSec -s EFI_SECTION_RAW -o out.sec in.bin # in.bin: 100 bytes out.sec is 104 bytes: the 100-byte payload plus the 4-byte EFI_COMMON_SECTION_HEADER. The Size field of the header reads 0x000068, matching out.sec's size that is calculated by SECTION_SIZE. Generated with the following Coccinelle semantic patch: ```smpl @@ EFI_COMMON_SECTION_HEADER *E; typedef UINT32; @@ ( - *(UINT32 *)(E->Size) & 0x00FFFFFF + SECTION_SIZE (E) | - *(UINT32 *)E->Size & 0x00FFFFFF + SECTION_SIZE (E) ) ``` Signed-off-by: Mingjie Shen <shen497@purdue.edu>
-rw-r--r--BaseTools/Source/C/GenSec/GenSec.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec/GenSec.c
index f675338a46..25304d84a3 100644
--- a/BaseTools/Source/C/GenSec/GenSec.c
+++ b/BaseTools/Source/C/GenSec/GenSec.c
@@ -1936,7 +1936,7 @@ Returns:
//
if (SectType != EFI_SECTION_ALL) {
SectionHeader = (EFI_COMMON_SECTION_HEADER *)OutFileBuffer;
- InputLength = *(UINT32 *)SectionHeader->Size & 0x00ffffff;
+ InputLength = SECTION_SIZE (SectionHeader);
if (InputLength == 0xffffff) {
InputLength = ((EFI_COMMON_SECTION_HEADER2 *)SectionHeader)->ExtendedSize;
}