Skip to content

Commit

Permalink
ensure that the EVP_CIPHER_CTX object is initialized
Browse files Browse the repository at this point in the history
PR: 1490
  • Loading branch information
Nils Larsch committed Feb 16, 2007
1 parent 85c6749 commit cc684e3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
9 changes: 6 additions & 3 deletions ssl/s2_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,18 @@ int ssl2_enc_init(SSL *s, int client)
((s->enc_read_ctx=(EVP_CIPHER_CTX *)
OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
goto err;

/* make sure it's intialized in case the malloc for enc_write_ctx fails
* and we exit with an error */
rs= s->enc_read_ctx;
EVP_CIPHER_CTX_init(rs);

if ((s->enc_write_ctx == NULL) &&
((s->enc_write_ctx=(EVP_CIPHER_CTX *)
OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
goto err;

rs= s->enc_read_ctx;
ws= s->enc_write_ctx;

EVP_CIPHER_CTX_init(rs);
EVP_CIPHER_CTX_init(ws);

num=c->key_len;
Expand Down
7 changes: 6 additions & 1 deletion ssl/s3_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ int ssl3_change_cipher_state(SSL *s, int which)
reuse_dd = 1;
else if ((s->enc_read_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)
goto err;
else
/* make sure it's intialized in case we exit later with an error */
EVP_CIPHER_CTX_init(s->enc_read_ctx);
dd= s->enc_read_ctx;
s->read_hash=m;
#ifndef OPENSSL_NO_COMP
Expand Down Expand Up @@ -280,6 +283,9 @@ int ssl3_change_cipher_state(SSL *s, int which)
reuse_dd = 1;
else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)
goto err;
else
/* make sure it's intialized in case we exit later with an error */
EVP_CIPHER_CTX_init(s->enc_write_ctx);
dd= s->enc_write_ctx;
s->write_hash=m;
#ifndef OPENSSL_NO_COMP
Expand All @@ -305,7 +311,6 @@ int ssl3_change_cipher_state(SSL *s, int which)

if (reuse_dd)
EVP_CIPHER_CTX_cleanup(dd);
EVP_CIPHER_CTX_init(dd);

p=s->s3->tmp.key_block;
i=EVP_MD_size(m);
Expand Down
11 changes: 6 additions & 5 deletions ssl/t1_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ int tls1_change_cipher_state(SSL *s, int which)
reuse_dd = 1;
else if ((s->enc_read_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)
goto err;
else
/* make sure it's intialized in case we exit later with an error */
EVP_CIPHER_CTX_init(s->enc_read_ctx);
dd= s->enc_read_ctx;
s->read_hash=m;
#ifndef OPENSSL_NO_COMP
Expand Down Expand Up @@ -327,10 +330,9 @@ int tls1_change_cipher_state(SSL *s, int which)
reuse_dd = 1;
else if ((s->enc_write_ctx=OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL)
goto err;
if ((s->enc_write_ctx == NULL) &&
((s->enc_write_ctx=(EVP_CIPHER_CTX *)
OPENSSL_malloc(sizeof(EVP_CIPHER_CTX))) == NULL))
goto err;
else
/* make sure it's intialized in case we exit later with an error */
EVP_CIPHER_CTX_init(s->enc_write_ctx);
dd= s->enc_write_ctx;
s->write_hash=m;
#ifndef OPENSSL_NO_COMP
Expand All @@ -357,7 +359,6 @@ int tls1_change_cipher_state(SSL *s, int which)

if (reuse_dd)
EVP_CIPHER_CTX_cleanup(dd);
EVP_CIPHER_CTX_init(dd);

p=s->s3->tmp.key_block;
i=EVP_MD_size(m);
Expand Down

0 comments on commit cc684e3

Please sign in to comment.