fix: panic in reading PCR values

Fix panic in reading PCR values.

Fixes: #13110

Signed-off-by: Noel Georgi <git@frezbo.dev>
(cherry picked from commit c81aa125c85d3886c5b9bb4d7f77ec2def104f21)
This commit is contained in:
Noel Georgi 2026-04-14 14:33:08 +05:30 committed by Andrey Smirnov
parent 67a34a6eb3
commit 9b8c1891bb
No known key found for this signature in database
GPG Key ID: 322C6F63F594CE7C

View File

@ -60,7 +60,11 @@ func ReadPCR(t transport.TPM, pcr int) ([]byte, error) {
return nil, fmt.Errorf("failed to read PCR: %w", err)
}
return pcrValue.PCRValues.Digests[0].Buffer, nil
if pcrValue != nil && len(pcrValue.PCRValues.Digests) > 0 {
return pcrValue.PCRValues.Digests[0].Buffer, nil
}
return nil, fmt.Errorf("PCR value for PCR %d is not available", pcr)
}
// PCRExtend hashes the input and extends the PCR with the hash.