Fix some undefined behaviour in ossltest engine
Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/5266)
This commit is contained in:
parent
0f41dc0e9e
commit
04e3bb045f
1 changed files with 11 additions and 5 deletions
|
@ -593,16 +593,20 @@ int ossltest_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|||
int ret;
|
||||
|
||||
tmpbuf = OPENSSL_malloc(inl);
|
||||
if (tmpbuf == NULL)
|
||||
|
||||
/* OPENSSL_malloc will return NULL if inl == 0 */
|
||||
if (tmpbuf == NULL && inl > 0)
|
||||
return -1;
|
||||
|
||||
/* Remember what we were asked to encrypt */
|
||||
if (tmpbuf != NULL)
|
||||
memcpy(tmpbuf, in, inl);
|
||||
|
||||
/* Go through the motions of encrypting it */
|
||||
ret = EVP_CIPHER_meth_get_do_cipher(EVP_aes_128_cbc())(ctx, out, in, inl);
|
||||
|
||||
/* Throw it all away and just use the plaintext as the output */
|
||||
if (tmpbuf != NULL)
|
||||
memcpy(out, tmpbuf, inl);
|
||||
OPENSSL_free(tmpbuf);
|
||||
|
||||
|
@ -626,12 +630,14 @@ int ossltest_aes128_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
|
|||
return -1;
|
||||
|
||||
/* Remember what we were asked to encrypt */
|
||||
if (tmpbuf != NULL)
|
||||
memcpy(tmpbuf, in, inl);
|
||||
|
||||
/* Go through the motions of encrypting it */
|
||||
EVP_CIPHER_meth_get_do_cipher(EVP_aes_128_gcm())(ctx, out, in, inl);
|
||||
|
||||
/* Throw it all away and just use the plaintext as the output */
|
||||
if (tmpbuf != NULL)
|
||||
memcpy(out, tmpbuf, inl);
|
||||
OPENSSL_free(tmpbuf);
|
||||
|
||||
|
|
Loading…
Reference in a new issue