mirror of
https://github.com/stefanberger/libtpms
synced 2026-08-10 02:17:06 +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
9d3d010951
commit
f9025d9b86
@ -217,6 +217,9 @@ LIB_EXPORT int FindNthSetBit(
|
||||
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