TPM2: Added check when parsing TPMLPCRSelection in case of selection of a PCR's index which exceeds max value permitted (#204)
TPM2: Added check when parsing TPMLPCRSelection in case of selection of a PCR's index which exceeds max value permitted (#204)

* TPM2: Added check when parsing TPMLPCRSelection in case of selection of a PCR's index which exceeds 8*sizeOfPCRSelect-1 to avoid panic runtime error

The current implementation makes use of `sizeOfPCRSelect` set to `3`. This means that the maximum size of the `pcrSelect` byte array in `tpmsPCRSelection` is `3`, which means it can only deal with the selection of PCRs from 0 to 23. Attempting to select PCR 24 for example (which might exist on some TPMs) leads to a 'panic: runtime error: index out of range [3] with length 3' since `ts.PCRs[byteNum] |= bytePos` tries to access index 3 of the byte array, which is out of range.

This can be fixed by adding a check beforehand, and skipping the PCR if it's index exceeds the maximum value permitted, independently of the value of `sizeOfPCRSelect`.

Signed-off-by: El Mostafa IDRASSI <4f7d950936bbf1990a778caf600b9e2de5a9ad28@tutanota.com>

* Return an error instead of skipping PCR indexes that are out of range.

Signed-off-by: El Mostafa IDRASSI <4f7d950936bbf1990a778caf600b9e2de5a9ad28@tutanota.com>
google/go-tpm