From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.92.68.18; helo=eur02-he1-obe.outbound.protection.outlook.com; envelope-from=marvin.haeuser@outlook.com; receiver=edk2-devel@lists.01.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-oln040092068018.outbound.protection.outlook.com [40.92.68.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 158CE222DE146 for ; Tue, 27 Feb 2018 08:41:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=tmRzyDi7JTohh/U0xOW5MJCqs/mDy6XmTbvdPL+29CQ=; b=Y3CN5HZVO2qenPLpbLOrtpk7xkosbQXi79FDAZcZWz+1QiMB5rLWvDUtCxu0qcuLmQJxvUy9LIyzreLaw2dXsx/hNLbD7dPhi2foUEbhmPO61qkoiemF3vG4Xm7GGKWN0v3YBetUuZOqwjUlwSbsxAnvpPpy33f8MfuRalQfVEQsnVCd3dw74qEbntXZwHBUQ/cVplT17BOu4NB2TOqWNUVQF0Hn3gV7UrwLjK2zyPEWT1RkvFj7Io4FnepRrz68qlYY/u7uIZBFUhj6bxb6X7zebLCdZIn5Dmdo2xVStzQ2tsgJ2wRrpkvm8+kubERPXX8r/FoV7pkw+1EeYYOIyg== Received: from VE1EUR02FT055.eop-EUR02.prod.protection.outlook.com (10.152.12.55) by VE1EUR02HT140.eop-EUR02.prod.protection.outlook.com (10.152.13.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.485.12; Tue, 27 Feb 2018 16:47:56 +0000 Received: from AM4PR06MB1491.eurprd06.prod.outlook.com (10.152.12.60) by VE1EUR02FT055.mail.protection.outlook.com (10.152.13.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.527.15 via Frontend Transport; Tue, 27 Feb 2018 16:47:56 +0000 Received: from AM4PR06MB1491.eurprd06.prod.outlook.com ([fe80::7d81:9d96:1051:d20d]) by AM4PR06MB1491.eurprd06.prod.outlook.com ([fe80::7d81:9d96:1051:d20d%14]) with mapi id 15.20.0527.021; Tue, 27 Feb 2018 16:47:55 +0000 From: =?iso-8859-1?Q?Marvin_H=E4user?= To: "edk2-devel@lists.01.org" CC: "michael.d.kinney@intel.com" , "liming.gao@intel.com" Thread-Topic: [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise operations. Thread-Index: AQHTr+q3IxS4cmiO9UyN5haxybivfg== Date: Tue, 27 Feb 2018 16:47:55 +0000 Message-ID: Accept-Language: de-DE, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:D42B290934F41088A6E79A6242AD488DE7045C65A583CA59A6E01E97D41956B8; UpperCasedChecksum:40BFECB72D53B3755229791815B1CD8888753DC0581D9BAA0A28F98292CF9AF6; SizeAsReceived:7101; Count:45 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [gtM5QJoTL8NN7jTATMJhuB+wOTAar7Qp] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VE1EUR02HT140; 6:4af40SOymnbWczbsg8TE3HWOR5Q3FzxdS6W6kzhSDa3/So7ILL02KSXqZBdTnX+1XPUu6zKqyHTHV3KnmoKTDaWBtFBX4eiIxoxK8hfzQ72bvy5ShGd1fxqXCrLHKSC3WaUM0i/dhespt5rqKc3hU6IkAlJdz0SDbT/h0q0m4NWrgkzQ2+o4XdXVTo9ioL84PUNwsPMr0mui9n1DgOhPR8pdLusKJTvPvYsAv+Au7WlmyOCo/tnZtjATl2AFlb/fkBakwEIv6WdbGCumMXbePz7ENzT1oDGk1DVsaFc+m7oBEad6Yci2wdAdznjJERygsHrSVoIlpA5iU/+KPPAScK4mKjXOp+GfNA3TeZslHz4=; 5:qgUuX6y3UocTmko2XIbtv1jWjBAAifkSPy64NMrkVbGhU6Bs9vZ62L6LxZ6w38dxeCRM0PhDvRQpUCR1RPaNLu7ImNJyKCYIUgsIwcGSb2uYrkWX0KKCSl4eGV2rweHhYcYSBZmfqRDUlx3xvu+0xNBOmosE54uROUb5OZkjkc8=; 24:kdZjMcHE9P1LESVGGUj+27DUNEI6HCTVy7JPYeRxfWdSA7c94X+W3FSBGmEmPTDygi6ofLOpZWI60LhbTKex1RFtwYS5KoUPND3Zue8cfTE=; 7:8VsU+aYIsJbYK9qdFCb/bUC7qxG2iHjE6y8aiswFoDF9O4zOEZ1LbkeMHaPdvH27vsmWJ6V/xlvGAdzfpIYRGMc5fYtnP3weNLvX4VM/ui+sMTa6Q4tRs/UwIpQpY8QhjjyJiMozoh1EWPY+ZC1qXI28EnFtyEqq0Ip4qO9Wn+5rzszeoqY1MKkZJiO9pOR6NSSxaEBJ8x1mJgoOp1lF5RYegXTO6QJpqnQXD1ygMVaNsQWQLHcAnHZp9nm+PfzO x-incomingheadercount: 45 x-eopattributedmessage: 0 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322404)(1603101448)(1601125374)(1701031045); SRVR:VE1EUR02HT140; x-ms-traffictypediagnostic: VE1EUR02HT140: x-ms-office365-filtering-correlation-id: 17686d18-e52e-45e2-e501-08d57e01d973 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(444000031); SRVR:VE1EUR02HT140; BCL:0; PCL:0; RULEID:; SRVR:VE1EUR02HT140; x-forefront-prvs: 05961EBAFC x-forefront-antispam-report: SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:VE1EUR02HT140; H:AM4PR06MB1491.eurprd06.prod.outlook.com; FPR:; SPF:None; LANG:; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17686d18-e52e-45e2-e501-08d57e01d973 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Feb 2018 16:47:55.8455 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR02HT140 Subject: [PATCH 1/2] MdePkg/Base.h: Ensure safe bitwise operations. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Feb 2018 16:41:53 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable As per the C standard, bit-level operations on signed integers are either undefined or implementation-defined. Hence, mark all BIT defines and shifts as unsigned to safely allow such operations. For the SIGNATURE macros, add several casts to account for int promotions, which might be signed. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marvin Haeuser --- MdePkg/Include/Base.h | 160 ++++++++++---------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h index a94182f08886..f108ed92eb0b 100644 --- a/MdePkg/Include/Base.h +++ b/MdePkg/Include/Base.h @@ -404,38 +404,38 @@ struct _LIST_ENTRY { #define MIN_INT32 (((INT32) -2147483647) - 1) #define MIN_INT64 (((INT64) -9223372036854775807LL) - 1) =20 -#define BIT0 0x00000001 -#define BIT1 0x00000002 -#define BIT2 0x00000004 -#define BIT3 0x00000008 -#define BIT4 0x00000010 -#define BIT5 0x00000020 -#define BIT6 0x00000040 -#define BIT7 0x00000080 -#define BIT8 0x00000100 -#define BIT9 0x00000200 -#define BIT10 0x00000400 -#define BIT11 0x00000800 -#define BIT12 0x00001000 -#define BIT13 0x00002000 -#define BIT14 0x00004000 -#define BIT15 0x00008000 -#define BIT16 0x00010000 -#define BIT17 0x00020000 -#define BIT18 0x00040000 -#define BIT19 0x00080000 -#define BIT20 0x00100000 -#define BIT21 0x00200000 -#define BIT22 0x00400000 -#define BIT23 0x00800000 -#define BIT24 0x01000000 -#define BIT25 0x02000000 -#define BIT26 0x04000000 -#define BIT27 0x08000000 -#define BIT28 0x10000000 -#define BIT29 0x20000000 -#define BIT30 0x40000000 -#define BIT31 0x80000000 +#define BIT0 0x00000001U +#define BIT1 0x00000002U +#define BIT2 0x00000004U +#define BIT3 0x00000008U +#define BIT4 0x00000010U +#define BIT5 0x00000020U +#define BIT6 0x00000040U +#define BIT7 0x00000080U +#define BIT8 0x00000100U +#define BIT9 0x00000200U +#define BIT10 0x00000400U +#define BIT11 0x00000800U +#define BIT12 0x00001000U +#define BIT13 0x00002000U +#define BIT14 0x00004000U +#define BIT15 0x00008000U +#define BIT16 0x00010000U +#define BIT17 0x00020000U +#define BIT18 0x00040000U +#define BIT19 0x00080000U +#define BIT20 0x00100000U +#define BIT21 0x00200000U +#define BIT22 0x00400000U +#define BIT23 0x00800000U +#define BIT24 0x01000000U +#define BIT25 0x02000000U +#define BIT26 0x04000000U +#define BIT27 0x08000000U +#define BIT28 0x10000000U +#define BIT29 0x20000000U +#define BIT30 0x40000000U +#define BIT31 0x80000000U #define BIT32 0x0000000100000000ULL #define BIT33 0x0000000200000000ULL #define BIT34 0x0000000400000000ULL @@ -469,28 +469,28 @@ struct _LIST_ENTRY { #define BIT62 0x4000000000000000ULL #define BIT63 0x8000000000000000ULL =20 -#define SIZE_1KB 0x00000400 -#define SIZE_2KB 0x00000800 -#define SIZE_4KB 0x00001000 -#define SIZE_8KB 0x00002000 -#define SIZE_16KB 0x00004000 -#define SIZE_32KB 0x00008000 -#define SIZE_64KB 0x00010000 -#define SIZE_128KB 0x00020000 -#define SIZE_256KB 0x00040000 -#define SIZE_512KB 0x00080000 -#define SIZE_1MB 0x00100000 -#define SIZE_2MB 0x00200000 -#define SIZE_4MB 0x00400000 -#define SIZE_8MB 0x00800000 -#define SIZE_16MB 0x01000000 -#define SIZE_32MB 0x02000000 -#define SIZE_64MB 0x04000000 -#define SIZE_128MB 0x08000000 -#define SIZE_256MB 0x10000000 -#define SIZE_512MB 0x20000000 -#define SIZE_1GB 0x40000000 -#define SIZE_2GB 0x80000000 +#define SIZE_1KB 0x00000400U +#define SIZE_2KB 0x00000800U +#define SIZE_4KB 0x00001000U +#define SIZE_8KB 0x00002000U +#define SIZE_16KB 0x00004000U +#define SIZE_32KB 0x00008000U +#define SIZE_64KB 0x00010000U +#define SIZE_128KB 0x00020000U +#define SIZE_256KB 0x00040000U +#define SIZE_512KB 0x00080000U +#define SIZE_1MB 0x00100000U +#define SIZE_2MB 0x00200000U +#define SIZE_4MB 0x00400000U +#define SIZE_8MB 0x00800000U +#define SIZE_16MB 0x01000000U +#define SIZE_32MB 0x02000000U +#define SIZE_64MB 0x04000000U +#define SIZE_128MB 0x08000000U +#define SIZE_256MB 0x10000000U +#define SIZE_512MB 0x20000000U +#define SIZE_1GB 0x40000000U +#define SIZE_2GB 0x80000000U #define SIZE_4GB 0x0000000100000000ULL #define SIZE_8GB 0x0000000200000000ULL #define SIZE_16GB 0x0000000400000000ULL @@ -524,28 +524,28 @@ struct _LIST_ENTRY { #define SIZE_4EB 0x4000000000000000ULL #define SIZE_8EB 0x8000000000000000ULL =20 -#define BASE_1KB 0x00000400 -#define BASE_2KB 0x00000800 -#define BASE_4KB 0x00001000 -#define BASE_8KB 0x00002000 -#define BASE_16KB 0x00004000 -#define BASE_32KB 0x00008000 -#define BASE_64KB 0x00010000 -#define BASE_128KB 0x00020000 -#define BASE_256KB 0x00040000 -#define BASE_512KB 0x00080000 -#define BASE_1MB 0x00100000 -#define BASE_2MB 0x00200000 -#define BASE_4MB 0x00400000 -#define BASE_8MB 0x00800000 -#define BASE_16MB 0x01000000 -#define BASE_32MB 0x02000000 -#define BASE_64MB 0x04000000 -#define BASE_128MB 0x08000000 -#define BASE_256MB 0x10000000 -#define BASE_512MB 0x20000000 -#define BASE_1GB 0x40000000 -#define BASE_2GB 0x80000000 +#define BASE_1KB 0x00000400U +#define BASE_2KB 0x00000800U +#define BASE_4KB 0x00001000U +#define BASE_8KB 0x00002000U +#define BASE_16KB 0x00004000U +#define BASE_32KB 0x00008000U +#define BASE_64KB 0x00010000U +#define BASE_128KB 0x00020000U +#define BASE_256KB 0x00040000U +#define BASE_512KB 0x00080000U +#define BASE_1MB 0x00100000U +#define BASE_2MB 0x00200000U +#define BASE_4MB 0x00400000U +#define BASE_8MB 0x00800000U +#define BASE_16MB 0x01000000U +#define BASE_32MB 0x02000000U +#define BASE_64MB 0x04000000U +#define BASE_128MB 0x08000000U +#define BASE_256MB 0x10000000U +#define BASE_512MB 0x20000000U +#define BASE_1GB 0x40000000U +#define BASE_2GB 0x80000000U #define BASE_4GB 0x0000000100000000ULL #define BASE_8GB 0x0000000200000000ULL #define BASE_16GB 0x0000000400000000ULL @@ -974,7 +974,7 @@ typedef UINTN RETURN_STATUS; @return The value specified by StatusCode with the highest bit set. =20 **/ -#define ENCODE_ERROR(StatusCode) ((RETURN_STATUS)(MAX_BIT | (StatusCod= e))) +#define ENCODE_ERROR(StatusCode) ((RETURN_STATUS)(MAX_BIT | (StatusCod= e##ULL))) =20 /** Produces a RETURN_STATUS code with the highest bit clear. @@ -1221,7 +1221,7 @@ typedef UINTN RETURN_STATUS; @return A 16-bit value built from the two ASCII characters specified by = A and B. =20 **/ -#define SIGNATURE_16(A, B) ((A) | (B << 8)) +#define SIGNATURE_16(A, B) ((UINT16)(A) | (UINT16)((UINT16)(B) << 8= U)) =20 /** Returns a 32-bit signature built from 4 ASCII characters. @@ -1238,7 +1238,7 @@ typedef UINTN RETURN_STATUS; C and D. =20 **/ -#define SIGNATURE_32(A, B, C, D) (SIGNATURE_16 (A, B) | (SIGNATURE_16 (C,= D) << 16)) +#define SIGNATURE_32(A, B, C, D) ((UINT32)SIGNATURE_16 (A, B) | (UINT32)(= (UINT32)SIGNATURE_16 (C, D) << 16U)) =20 /** Returns a 64-bit signature built from 8 ASCII characters. @@ -1260,7 +1260,7 @@ typedef UINTN RETURN_STATUS; =20 **/ #define SIGNATURE_64(A, B, C, D, E, F, G, H) \ - (SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << = 32)) + ((UINT64)SIGNATURE_32 (A, B, C, D) | ((UINT64) ((UINT64)SIGNATURE_32 (= E, F, G, H)) << 32U)) =20 #if defined(_MSC_EXTENSIONS) && !defined (__INTEL_COMPILER) && !defined (M= DE_CPU_EBC) void * _ReturnAddress(void); --=20 2.16.0.windows.2