]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/AtaAtapiPassThru: Fix possible out of range left shift
authorHao Wu <hao.a.wu@intel.com>
Tue, 19 Sep 2017 08:11:29 +0000 (16:11 +0800)
committerHao Wu <hao.a.wu@intel.com>
Fri, 29 Sep 2017 08:14:17 +0000 (16:14 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=699

Within function AhciModeInitialization(), left shift operations of 'BIT0'
in the following statements:
"if ((PortImplementBitMap & (BIT0 << Port)) != 0) {"

will incur possible out of range left shift when Port is 31, since
"1 << 31" is possible to exceed the range of type 'int' (signed).

According to the C11 spec, Section 6.5.7:
> 4 The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated
>   bits are filled with zeros. If E1 has an unsigned type, the value
>   of the result is E1 * 2^E2 , reduced modulo one more than the
>   maximum value representable in the result type. If E1 has a signed
>   type and nonnegative value, and E1 * 2^E2 is representable in the
>   result type, then that is the resulting value; otherwise, the
>   behavior is undefined.

This commit explicitly cast 'BIT0' with UINT32 to resolve this issue.

Cc: Steven Shi <steven.shi@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c

index b954de81015e219fa558e1e4d2d038e2cf11a224..e6de5d65bc6c2c556c234744b1fce7b1648c6544 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The file for AHCI mode of ATA host controller.\r
 \r
-  Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>\r
   (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -2314,7 +2314,7 @@ AhciModeInitialization (
   }\r
 \r
   for (Port = 0; Port < EFI_AHCI_MAX_PORTS; Port ++) {\r
-    if ((PortImplementBitMap & (BIT0 << Port)) != 0) {\r
+    if ((PortImplementBitMap & (((UINT32)BIT0) << Port)) != 0) {\r
       //\r
       // According to AHCI spec, MaxPortNumber should be equal or greater than the number of implemented ports.\r
       //\r