From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Fri, 12 Apr 2019 16:31:40 -0700 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 073FD308A968; Fri, 12 Apr 2019 23:31:40 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-65.rdu2.redhat.com [10.10.120.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id B746960606; Fri, 12 Apr 2019 23:31:38 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Bob Feng , Liming Gao , Yonghong Zhu Subject: [PATCH 03/10] BaseTools/PiFirmwareFile: fix undefined behavior in SECTION_SIZE Date: Sat, 13 Apr 2019 01:31:21 +0200 Message-Id: <20190412233128.4756-4-lersek@redhat.com> In-Reply-To: <20190412233128.4756-1-lersek@redhat.com> References: <20190412233128.4756-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 12 Apr 2019 23:31:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable Sync SECTION_SIZE() and EFI_COMMON_SECTION_HEADER_UNION from MdePkg to BaseTools, from an earlier patch in this series. Cc: Bob Feng Cc: Liming Gao Cc: Yonghong Zhu Bugzilla: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1710 Signed-off-by: Laszlo Ersek --- BaseTools/Source/C/Include/Common/PiFirmwareFile.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/C/Include/Common/PiFirmwareFile.h b/BaseToo= ls/Source/C/Include/Common/PiFirmwareFile.h index 5bc871df4855..0ce89e1074a7 100644 --- a/BaseTools/Source/C/Include/Common/PiFirmwareFile.h +++ b/BaseTools/Source/C/Include/Common/PiFirmwareFile.h @@ -144,16 +144,21 @@ typedef UINT8 EFI_SECTION_TYPE; #define EFI_SECTION_PEI_DEPEX 0x1B #define EFI_SECTION_SMM_DEPEX 0x1C =20 typedef struct { UINT8 Size[3]; EFI_SECTION_TYPE Type; } EFI_COMMON_SECTION_HEADER; =20 +typedef union { + EFI_COMMON_SECTION_HEADER Hdr; + UINT32 Uint32; +} EFI_COMMON_SECTION_HEADER_UNION; + typedef struct { UINT8 Size[3]; EFI_SECTION_TYPE Type; UINT32 ExtendedSize; } EFI_COMMON_SECTION_HEADER2; =20 #define MAX_SECTION_SIZE 0x1000000 =20 @@ -296,17 +301,17 @@ typedef struct { =20 typedef struct { EFI_COMMON_SECTION_HEADER2 CommonHeader; UINT16 BuildNumber; CHAR16 VersionString[1]; } EFI_VERSION_SECTION2; =20 #define SECTION_SIZE(SectionHeaderPtr) \ - ((UINT32) (*((UINT32 *) ((EFI_COMMON_SECTION_HEADER *) SectionHeader= Ptr)->Size) & 0x00ffffff)) + (((EFI_COMMON_SECTION_HEADER_UNION *) (SectionHeaderPtr))->Uint32 & = 0x00ffffff) =20 #pragma pack() =20 typedef union { EFI_COMMON_SECTION_HEADER *CommonHeader; EFI_COMPRESSION_SECTION *CompressionSection; EFI_GUID_DEFINED_SECTION *GuidDefinedSection; EFI_PE32_SECTION *Pe32Section; --=20 2.19.1.3.g30247aa5d201