mirror of https://github.com/openssl/openssl.git
test: fix coverity 1451550: unchecked return value
Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14615)
This commit is contained in:
parent
f47865156a
commit
3352a4f6fa
|
|
@ -283,11 +283,12 @@ static int send_record(BIO *rbio, unsigned char type, uint64_t seqnr,
|
|||
unsigned char lenbytes[2];
|
||||
EVP_MAC *hmac;
|
||||
EVP_MAC_CTX *ctx;
|
||||
EVP_CIPHER_CTX *enc_ctx;
|
||||
EVP_CIPHER_CTX *enc_ctx = NULL;
|
||||
unsigned char iv[16];
|
||||
unsigned char pad;
|
||||
unsigned char *enc;
|
||||
OSSL_PARAM params[2];
|
||||
int ret = 0;
|
||||
|
||||
seq[0] = (seqnr >> 40) & 0xff;
|
||||
seq[1] = (seqnr >> 32) & 0xff;
|
||||
|
|
@ -305,23 +306,26 @@ static int send_record(BIO *rbio, unsigned char type, uint64_t seqnr,
|
|||
memcpy(enc, msg, len);
|
||||
|
||||
/* Append HMAC to data */
|
||||
hmac = EVP_MAC_fetch(NULL, "HMAC", NULL);
|
||||
if ((hmac = EVP_MAC_fetch(NULL, "HMAC", NULL)) == NULL)
|
||||
return 0;
|
||||
ctx = EVP_MAC_CTX_new(hmac);
|
||||
EVP_MAC_free(hmac);
|
||||
if (ctx == NULL)
|
||||
return 0;
|
||||
params[0] = OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST,
|
||||
"SHA1", 0);
|
||||
params[1] = OSSL_PARAM_construct_end();
|
||||
EVP_MAC_init(ctx, mac_key, 20, params);
|
||||
EVP_MAC_update(ctx, epoch, 2);
|
||||
EVP_MAC_update(ctx, seq, 6);
|
||||
EVP_MAC_update(ctx, &type, 1);
|
||||
EVP_MAC_update(ctx, ver, 2); /* Version */
|
||||
lenbytes[0] = (unsigned char)(len >> 8);
|
||||
lenbytes[1] = (unsigned char)(len);
|
||||
EVP_MAC_update(ctx, lenbytes, 2); /* Length */
|
||||
EVP_MAC_update(ctx, enc, len); /* Finally the data itself */
|
||||
EVP_MAC_final(ctx, enc + len, NULL, SHA_DIGEST_LENGTH);
|
||||
EVP_MAC_CTX_free(ctx);
|
||||
if (!EVP_MAC_init(ctx, mac_key, 20, params)
|
||||
|| !EVP_MAC_update(ctx, epoch, 2)
|
||||
|| !EVP_MAC_update(ctx, seq, 6)
|
||||
|| !EVP_MAC_update(ctx, &type, 1)
|
||||
|| !EVP_MAC_update(ctx, ver, 2) /* Version */
|
||||
|| !EVP_MAC_update(ctx, lenbytes, 2) /* Length */
|
||||
|| !EVP_MAC_update(ctx, enc, len) /* Finally the data itself */
|
||||
|| !EVP_MAC_final(ctx, enc + len, NULL, SHA_DIGEST_LENGTH))
|
||||
goto end;
|
||||
|
||||
/* Append padding bytes */
|
||||
len += SHA_DIGEST_LENGTH;
|
||||
|
|
@ -330,11 +334,12 @@ static int send_record(BIO *rbio, unsigned char type, uint64_t seqnr,
|
|||
} while (len % 16);
|
||||
|
||||
/* Generate IV, and encrypt */
|
||||
RAND_bytes(iv, sizeof(iv));
|
||||
enc_ctx = EVP_CIPHER_CTX_new();
|
||||
EVP_CipherInit_ex(enc_ctx, EVP_aes_128_cbc(), NULL, enc_key, iv, 1);
|
||||
EVP_Cipher(enc_ctx, enc, enc, len);
|
||||
EVP_CIPHER_CTX_free(enc_ctx);
|
||||
if (!TEST_true(RAND_bytes(iv, sizeof(iv)))
|
||||
|| !TEST_ptr(enc_ctx = EVP_CIPHER_CTX_new())
|
||||
|| !TEST_true(EVP_CipherInit_ex(enc_ctx, EVP_aes_128_cbc(), NULL,
|
||||
enc_key, iv, 1))
|
||||
|| !TEST_int_ge(EVP_Cipher(enc_ctx, enc, enc, len), 0))
|
||||
goto end;
|
||||
|
||||
/* Finally write header (from fragmented variables), IV and encrypted record */
|
||||
BIO_write(rbio, &type, 1);
|
||||
|
|
@ -347,9 +352,12 @@ static int send_record(BIO *rbio, unsigned char type, uint64_t seqnr,
|
|||
|
||||
BIO_write(rbio, iv, sizeof(iv));
|
||||
BIO_write(rbio, enc, len);
|
||||
|
||||
ret = 1;
|
||||
end:
|
||||
EVP_MAC_CTX_free(ctx);
|
||||
EVP_CIPHER_CTX_free(enc_ctx);
|
||||
OPENSSL_free(enc);
|
||||
return 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int send_finished(SSL *s, BIO *rbio)
|
||||
|
|
|
|||
Loading…
Reference in New Issue