mirror of
https://github.com/stefanberger/libtpms
synced 2026-08-09 00:57:35 +00:00
tpm2: Filter bad input values to avoid underflow in FindNthSetBit (Coverity)
Address the following Coverity complaint (1550494) by filtering out bad input values: "Expression i--, which is equal to 65535, where i is known to be equal to 0, underflows the type that receives it, an unsigned integer 16 bits wide." aSize is typcially 2048 and n is always >= 1 per the input parameter. Therefore no side-effects are expected from this filter. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
parent
d7f5fc3644
commit
5af7abe1f6
@ -215,6 +215,10 @@ FindNthSetBit(
|
||||
int retValue;
|
||||
UINT32 sum = 0;
|
||||
BYTE sel;
|
||||
|
||||
if (n < 1 || aSize < 1) // libtpms added begin: Coverity 1550494
|
||||
return -1; // libtpms end
|
||||
|
||||
//find the bit
|
||||
for(i = 0; (i < (int)aSize) && (sum < n); i++)
|
||||
sum += BitsInByte(a[i]);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user