diff options
author | Laszlo Ersek <lersek@redhat.com> | 2019-04-12 15:10:09 +0200 |
---|---|---|
committer | Laszlo Ersek <lersek@redhat.com> | 2019-04-24 17:30:57 +0200 |
commit | d3b3ee09a675cca1617a21a4f967457f92ebe3a6 (patch) | |
tree | 857a93000ac7e7c04d309afe28b4c99c23aa608d /BaseTools | |
parent | fc76bbd94df7f5a7f1f3939c7e93a113a6d36270 (diff) | |
download | edk2-d3b3ee09a675cca1617a21a4f967457f92ebe3a6.tar.gz edk2-d3b3ee09a675cca1617a21a4f967457f92ebe3a6.tar.bz2 edk2-d3b3ee09a675cca1617a21a4f967457f92ebe3a6.zip |
BaseTools/PiFirmwareFile: fix undefined behavior in SECTION_SIZE
Sync SECTION_SIZE() from MdePkg to BaseTools, from an earlier patch in
this series.
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=1710
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Diffstat (limited to 'BaseTools')
-rw-r--r-- | BaseTools/Source/C/Include/Common/PiFirmwareFile.h | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/BaseTools/Source/C/Include/Common/PiFirmwareFile.h b/BaseTools/Source/C/Include/Common/PiFirmwareFile.h index 5bc871df48..7d8acb669b 100644 --- a/BaseTools/Source/C/Include/Common/PiFirmwareFile.h +++ b/BaseTools/Source/C/Include/Common/PiFirmwareFile.h @@ -300,8 +300,15 @@ typedef struct { CHAR16 VersionString[1];
} EFI_VERSION_SECTION2;
-#define SECTION_SIZE(SectionHeaderPtr) \
- ((UINT32) (*((UINT32 *) ((EFI_COMMON_SECTION_HEADER *) SectionHeaderPtr)->Size) & 0x00ffffff))
+//
+// The argument passed as the SectionHeaderPtr parameter to the SECTION_SIZE()
+// function-like macro below must not have side effects: SectionHeaderPtr is
+// evaluated multiple times.
+//
+#define SECTION_SIZE(SectionHeaderPtr) ((UINT32) ( \
+ (((EFI_COMMON_SECTION_HEADER *) (SectionHeaderPtr))->Size[0] ) | \
+ (((EFI_COMMON_SECTION_HEADER *) (SectionHeaderPtr))->Size[1] << 8) | \
+ (((EFI_COMMON_SECTION_HEADER *) (SectionHeaderPtr))->Size[2] << 16)))
#pragma pack()
|