From: Jason Andryuk Date: Thu, 6 May 2021 13:59:20 +0000 (-0400) Subject: vtpmmgr: Remove bogus cast from TPM2_GetRandom X-Git-Tag: archive/raspbian/4.16.0+51-g0941d6cb-1+rpi1~2^2~42^2~541 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=7f4276fad8f0bfba5bb3fd012bf2df51c05fcf02;p=xen.git 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 Signed-off-by: Jason Andryuk Reviewed-by: Samuel Thibault Reviewed-by: Daniel P. Smith --- 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;