MdeModulePkg/AtaAtapiPassThru: fix buffer overflow issue introduced by previous patch(r13932).

Signed-off-by: Feng Tian <feng.tian@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13941 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
erictian 2012-11-14 05:12:40 +00:00
parent 5f6aee0f72
commit 467cacbf77
1 changed files with 10 additions and 1 deletions

View File

@ -1908,6 +1908,7 @@ AhciCreateTransferDescriptor (
VOID *Buffer; VOID *Buffer;
UINT32 Capability; UINT32 Capability;
UINT32 PortImplementBitMap;
UINT8 MaxPortNumber; UINT8 MaxPortNumber;
UINT8 MaxCommandSlotNumber; UINT8 MaxCommandSlotNumber;
BOOLEAN Support64Bit; BOOLEAN Support64Bit;
@ -1923,12 +1924,20 @@ AhciCreateTransferDescriptor (
// Collect AHCI controller information // Collect AHCI controller information
// //
Capability = AhciReadReg(PciIo, EFI_AHCI_CAPABILITY_OFFSET); Capability = AhciReadReg(PciIo, EFI_AHCI_CAPABILITY_OFFSET);
MaxPortNumber = (UINT8) ((Capability & 0x1F) + 1);
// //
// Get the number of command slots per port supported by this HBA. // Get the number of command slots per port supported by this HBA.
// //
MaxCommandSlotNumber = (UINT8) (((Capability & 0x1F00) >> 8) + 1); MaxCommandSlotNumber = (UINT8) (((Capability & 0x1F00) >> 8) + 1);
Support64Bit = (BOOLEAN) (((Capability & BIT31) != 0) ? TRUE : FALSE); Support64Bit = (BOOLEAN) (((Capability & BIT31) != 0) ? TRUE : FALSE);
PortImplementBitMap = AhciReadReg(PciIo, EFI_AHCI_PI_OFFSET);
//
// Get the highest bit of implemented ports which decides how many bytes are allocated for recived FIS.
//
MaxPortNumber = (UINT8)(UINTN)(HighBitSet32(PortImplementBitMap) + 1);
if (MaxPortNumber == 0) {
return EFI_DEVICE_ERROR;
}
MaxReceiveFisSize = MaxPortNumber * sizeof (EFI_AHCI_RECEIVED_FIS); MaxReceiveFisSize = MaxPortNumber * sizeof (EFI_AHCI_RECEIVED_FIS);
Status = PciIo->AllocateBuffer ( Status = PciIo->AllocateBuffer (