summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Andryuk <jandryuk@gmail.com>2021-05-06 09:59:20 -0400
committerAndrew Cooper <andrew.cooper3@citrix.com>2021-05-10 14:50:33 +0100
commit7f4276fad8f0bfba5bb3fd012bf2df51c05fcf02 (patch)
tree964577ce6acf6563322d51974e1fb6003015cc26
parent64d00dd126b3dfa4370805f1dc3d7c1ddb6a130d (diff)
vtpmmgr: Remove bogus cast from TPM2_GetRandom
The UINT32 <-> UINT16 casting in TPM2_GetRandom is incorrect. Use a local UINT16 as needed for the TPM hardware command and assign the result. Suggested-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Signed-off-by: Jason Andryuk <jandryuk@gmail.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Reviewed-by: Daniel P. Smith <dpsmith@apertussolutions.com>
-rw-r--r--stubdom/vtpmmgr/tpm2.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/stubdom/vtpmmgr/tpm2.c b/stubdom/vtpmmgr/tpm2.c
index 655e6d164c..ebd06eac74 100644
--- a/stubdom/vtpmmgr/tpm2.c
+++ b/stubdom/vtpmmgr/tpm2.c
@@ -427,15 +427,22 @@ abort_egress:
TPM_RC TPM2_GetRandom(UINT32 * bytesRequested, BYTE * randomBytes)
{
+ UINT16 bytesReq;
TPM_BEGIN(TPM_ST_NO_SESSIONS, TPM_CC_GetRandom);
- ptr = pack_UINT16(ptr, (UINT16)*bytesRequested);
+ if (*bytesRequested > UINT16_MAX)
+ bytesReq = UINT16_MAX;
+ else
+ bytesReq = *bytesRequested;
+
+ ptr = pack_UINT16(ptr, bytesReq);
TPM_TRANSMIT();
TPM_UNPACK_VERIFY();
- ptr = unpack_UINT16(ptr, (UINT16 *)bytesRequested);
- ptr = unpack_TPM_BUFFER(ptr, randomBytes, *bytesRequested);
+ ptr = unpack_UINT16(ptr, &bytesReq);
+ *bytesRequested = bytesReq;
+ ptr = unpack_TPM_BUFFER(ptr, randomBytes, bytesReq);
abort_egress:
return status;