tpm2: Prevent a potential buffer overrun (Coverity)

Prevent a potential buffer overrun by checking that EVP_DecryptUpdate()
has not overrun the buffer it was passed in, so this overrun should
never occurr unless EVP_DecryptUpdate() was wrong. Also the pAssert above
it should have taken care of it already.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2021-02-21 08:24:35 -05:00 committed by Stefan Berger
parent f19282b243
commit 31d4c1dcb6

View File

@ -702,7 +702,8 @@ CryptSymmetricDecrypt(
pAssert((int)buffersize >= outlen1);
if (EVP_DecryptFinal(ctx, &buffer[outlen1], &outlen2) != 1)
if ((int)buffersize <= outlen1 /* coverity */ ||
EVP_DecryptFinal(ctx, &buffer[outlen1], &outlen2) != 1)
ERROR_RETURN(TPM_RC_FAILURE);
pAssert((int)buffersize >= outlen1 + outlen2);