tpm2: Print error message when invalid hash algorithm id appears (Coverity)

In case a hash algorithm id has a value >= 64 print out and error. This
should never occur since any hash algorithm id should have been set through
unmarshalling or by TPM 2-internal code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2024-07-14 21:14:07 -04:00 committed by Stefan Berger
parent ee141c60e0
commit e3520059cf

View File

@ -863,7 +863,12 @@ pcrbanks_algs_active(const TPML_PCR_SELECTION *pcrAllocated)
for(i = 0; i < pcrAllocated->count; i++) {
for (j = 0; j < pcrAllocated->pcrSelections[i].sizeofSelect; j++) {
if (pcrAllocated->pcrSelections[i].pcrSelect[j]) {
algs_active |= ((UINT64)1 << pcrAllocated->pcrSelections[i].hash);
if (pcrAllocated->pcrSelections[i].hash >= 64) {
TPMLIB_LogTPM2Error("pcrbanks_algs_active: invalid hash alg id: %d\n",
pcrAllocated->pcrSelections[i].hash);
} else {
algs_active |= ((UINT64)1 << pcrAllocated->pcrSelections[i].hash);
}
break;
}
}