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 00860abce3
commit 5710d697bf

View File

@ -703,7 +703,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);