amd/agesa/f1?/Lib/amdlib.c: Integer overflow in loop construct

The semantics of this loop relies on an integer overflow in Index >=0
that implies a return value of (UINT8)-1 which around wraps to 0xFF, or
VOLT_UNSUPPORTED.

Change-Id: I44d68973d0a80093350b2a8a4d3b46bfbb57917a
Signed-off-by: Edward O'Callaghan <eocallaghan@alterapraxis.com>
Reviewed-on: http://review.coreboot.org/5801
Tested-by: build bot (Jenkins)
Reviewed-by: Marc Jones <marc.jones@se-eng.com>
This commit is contained in:
Edward O'Callaghan 2014-05-22 03:36:22 +10:00 committed by Marc Jones
parent 2c9e370646
commit 3312ed7e7a
5 changed files with 15 additions and 15 deletions

View File

@ -344,11 +344,11 @@ LibAmdBitScanReverse (
IN UINT32 value IN UINT32 value
) )
{ {
UINTN Index; UINT8 Index;
for (Index = 31; Index >= 0; Index--){ for (Index = 31; Index >= 0; Index--){
if (value & (1 << Index)) break; if (value & (1 << Index)) return Index;
} }
return (UINT8) Index; return 0xFF;
} }
VOID VOID
LibAmdMsrRead ( LibAmdMsrRead (

View File

@ -348,11 +348,11 @@ LibAmdBitScanReverse (
IN UINT32 value IN UINT32 value
) )
{ {
UINTN Index; UINT8 Index;
for (Index = 31; Index >= 0; Index--){ for (Index = 31; Index >= 0; Index--){
if (value & (1 << Index)) break; if (value & (1 << Index)) return Index;
} }
return (UINT8) Index; return 0xFF;
} }
VOID VOID
LibAmdMsrRead ( LibAmdMsrRead (

View File

@ -348,11 +348,11 @@ LibAmdBitScanReverse (
IN UINT32 value IN UINT32 value
) )
{ {
UINTN Index; UINT8 Index;
for (Index = 31; Index >= 0; Index--){ for (Index = 31; Index >= 0; Index--){
if (value & (1 << Index)) break; if (value & (1 << Index)) return Index;
} }
return (UINT8) Index; return 0xFF;
} }
VOID VOID
LibAmdMsrRead ( LibAmdMsrRead (

View File

@ -348,11 +348,11 @@ LibAmdBitScanReverse (
IN UINT32 value IN UINT32 value
) )
{ {
UINTN Index; UINT8 Index;
for (Index = 31; Index >= 0; Index--){ for (Index = 31; Index >= 0; Index--){
if (value & (1 << Index)) break; if (value & (1 << Index)) return Index;
} }
return (UINT8) Index; return 0xFF;
} }
UINT64 UINT64

View File

@ -359,11 +359,11 @@ LibAmdBitScanReverse (
IN UINT32 value IN UINT32 value
) )
{ {
UINTN Index; UINT8 Index;
for (Index = 31; Index >= 0; Index--){ for (Index = 31; Index >= 0; Index--){
if (value & (1 << Index)) break; if (value & (1 << Index)) return Index;
} }
return (UINT8) Index; return 0xFF;
} }
VOID VOID
LibAmdMsrRead ( LibAmdMsrRead (