{
BIO_SSL *bs;
- bs = (BIO_SSL *)malloc(sizeof(BIO_SSL));
+ bs = calloc(1, sizeof(BIO_SSL));
if (bs == NULL) {
BIOerr(BIO_F_SSL_NEW, ERR_R_MALLOC_FAILURE);
return (0);
}
- memset(bs, 0, sizeof(BIO_SSL));
bi->init = 0;
bi->ptr = (char *)bs;
bi->flags = 0;
unsigned char *buf = NULL;
unsigned char *bitmask = NULL;
- frag = (hm_fragment *)malloc(sizeof(hm_fragment));
+ frag = malloc(sizeof(hm_fragment));
if (frag == NULL)
return NULL;
if (frag_len) {
- buf = (unsigned char *)malloc(frag_len);
+ buf = malloc(frag_len);
if (buf == NULL) {
free(frag);
return NULL;
/* Initialize reassembly bitmask if necessary */
if (reassembly) {
- bitmask = (unsigned char *)malloc(RSMBLY_BITMASK_SIZE(frag_len));
+ bitmask = malloc(RSMBLY_BITMASK_SIZE(frag_len));
if (bitmask == NULL) {
if (buf != NULL)
free(buf);
POINT_CONVERSION_UNCOMPRESSED,
NULL, 0, NULL);
- encodedPoint = (unsigned char *)
- malloc(encoded_pt_len *
- sizeof(unsigned char));
+ encodedPoint = malloc(encoded_pt_len);
bn_ctx = BN_CTX_new();
if ((encodedPoint == NULL) ||
POINT_CONVERSION_UNCOMPRESSED,
NULL, 0, NULL);
- encodedPoint = (unsigned char *)
- malloc(encodedlen*sizeof(unsigned char));
+ encodedPoint = malloc(encodedlen);
bn_ctx = BN_CTX_new();
if ((encodedPoint == NULL) || (bn_ctx == NULL)) {
POINT_CONVERSION_UNCOMPRESSED,
NULL, 0, NULL);
- encodedPoint =
- (unsigned char *)malloc(
- encoded_pt_len * sizeof(unsigned char));
+ encodedPoint = malloc(encoded_pt_len);
bn_ctx = BN_CTX_new();
if ((encodedPoint == NULL) ||
{
SSL3_STATE *s3;
- if ((s3 = malloc(sizeof *s3)) == NULL)
+ if ((s3 = calloc(1, sizeof *s3)) == NULL)
goto err;
- memset(s3, 0, sizeof *s3);
memset(s3->rrec.seq_num, 0, sizeof(s3->rrec.seq_num));
memset(s3->wrec.seq_num, 0, sizeof(s3->wrec.seq_num));
POINT_CONVERSION_UNCOMPRESSED,
NULL, 0, NULL);
- encodedPoint = (unsigned char *)
- malloc(encodedlen*sizeof(unsigned char));
+ encodedPoint = malloc(encodedlen);
bn_ctx = BN_CTX_new();
if ((encodedPoint == NULL) || (bn_ctx == NULL)) {
{
BIO_SSL *bs;
- bs = (BIO_SSL *)malloc(sizeof(BIO_SSL));
+ bs = calloc(1, sizeof(BIO_SSL));
if (bs == NULL) {
BIOerr(BIO_F_SSL_NEW, ERR_R_MALLOC_FAILURE);
return (0);
}
- memset(bs, 0, sizeof(BIO_SSL));
bi->init = 0;
bi->ptr = (char *)bs;
bi->flags = 0;
unsigned char *buf = NULL;
unsigned char *bitmask = NULL;
- frag = (hm_fragment *)malloc(sizeof(hm_fragment));
+ frag = malloc(sizeof(hm_fragment));
if (frag == NULL)
return NULL;
if (frag_len) {
- buf = (unsigned char *)malloc(frag_len);
+ buf = malloc(frag_len);
if (buf == NULL) {
free(frag);
return NULL;
/* Initialize reassembly bitmask if necessary */
if (reassembly) {
- bitmask = (unsigned char *)malloc(RSMBLY_BITMASK_SIZE(frag_len));
+ bitmask = malloc(RSMBLY_BITMASK_SIZE(frag_len));
if (bitmask == NULL) {
if (buf != NULL)
free(buf);
POINT_CONVERSION_UNCOMPRESSED,
NULL, 0, NULL);
- encodedPoint = (unsigned char *)
- malloc(encoded_pt_len *
- sizeof(unsigned char));
+ encodedPoint = malloc(encoded_pt_len);
bn_ctx = BN_CTX_new();
if ((encodedPoint == NULL) ||
POINT_CONVERSION_UNCOMPRESSED,
NULL, 0, NULL);
- encodedPoint = (unsigned char *)
- malloc(encodedlen*sizeof(unsigned char));
+ encodedPoint = malloc(encodedlen);
bn_ctx = BN_CTX_new();
if ((encodedPoint == NULL) || (bn_ctx == NULL)) {
POINT_CONVERSION_UNCOMPRESSED,
NULL, 0, NULL);
- encodedPoint =
- (unsigned char *)malloc(
- encoded_pt_len * sizeof(unsigned char));
+ encodedPoint = malloc(encoded_pt_len);
bn_ctx = BN_CTX_new();
if ((encodedPoint == NULL) ||
reuse_dd = 1;
else if ((s->enc_read_ctx = malloc(sizeof(EVP_CIPHER_CTX))) == NULL)
goto err;
- else
+ else {
/* make sure it's intialized in case we exit later with an error */
- EVP_CIPHER_CTX_init(s->enc_read_ctx);
+ EVP_CIPHER_CTX_init(s->enc_read_ctx);
+ }
dd = s->enc_read_ctx;
ssl_replace_hash(&s->read_hash, m);
goto err2;
}
if (s->s3->rrec.comp == NULL)
- s->s3->rrec.comp = (unsigned char *)
- malloc(SSL3_RT_MAX_PLAIN_LENGTH);
+ s->s3->rrec.comp = malloc(SSL3_RT_MAX_PLAIN_LENGTH);
if (s->s3->rrec.comp == NULL)
goto err;
}
reuse_dd = 1;
else if ((s->enc_write_ctx = malloc(sizeof(EVP_CIPHER_CTX))) == NULL)
goto err;
- else
+ else {
/* make sure it's intialized in case we exit later with an error */
- EVP_CIPHER_CTX_init(s->enc_write_ctx);
+ EVP_CIPHER_CTX_init(s->enc_write_ctx);
+ }
dd = s->enc_write_ctx;
ssl_replace_hash(&s->write_hash, m);
#ifndef OPENSSL_NO_COMP
/* Allocate handshake_dgst array */
ssl3_free_digest_list(s);
- s->s3->handshake_dgst = malloc(SSL_MAX_DIGEST * sizeof(EVP_MD_CTX *));
- memset(s->s3->handshake_dgst, 0, SSL_MAX_DIGEST *sizeof(EVP_MD_CTX *));
+ s->s3->handshake_dgst = calloc(SSL_MAX_DIGEST, sizeof(EVP_MD_CTX *));
hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata);
if (hdatalen <= 0) {
SSLerr(SSL_F_SSL3_DIGEST_CACHED_RECORDS, SSL_R_BAD_HANDSHAKE_LENGTH);
{
SSL3_STATE *s3;
- if ((s3 = malloc(sizeof *s3)) == NULL)
+ if ((s3 = calloc(1, sizeof *s3)) == NULL)
goto err;
- memset(s3, 0, sizeof *s3);
memset(s3->rrec.seq_num, 0, sizeof(s3->rrec.seq_num));
memset(s3->wrec.seq_num, 0, sizeof(s3->wrec.seq_num));
POINT_CONVERSION_UNCOMPRESSED,
NULL, 0, NULL);
- encodedPoint = (unsigned char *)
- malloc(encodedlen*sizeof(unsigned char));
+ encodedPoint = malloc(encodedlen);
bn_ctx = BN_CTX_new();
if ((encodedPoint == NULL) || (bn_ctx == NULL)) {
{
CERT *ret;
- ret = (CERT *)malloc(sizeof(CERT));
+ ret = calloc(1, sizeof(CERT));
if (ret == NULL) {
SSLerr(SSL_F_SSL_CERT_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
}
- memset(ret, 0, sizeof(CERT));
-
ret->key = &(ret->pkeys[SSL_PKEY_RSA_ENC]);
ret->references = 1;
ssl_cert_set_default_md(ret);
CERT *ret;
int i;
- ret = (CERT *)malloc(sizeof(CERT));
+ ret = calloc(1, sizeof(CERT));
if (ret == NULL) {
SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE);
return (NULL);
}
- memset(ret, 0, sizeof(CERT));
-
ret->key = &ret->pkeys[cert->key - &cert->pkeys[0]];
/* or ret->key = ret->pkeys + (cert->key - cert->pkeys),
* if you find that more readable */
{
SESS_CERT *ret;
- ret = malloc(sizeof *ret);
+ ret = calloc(1, sizeof *ret);
if (ret == NULL) {
SSLerr(SSL_F_SSL_SESS_CERT_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
}
-
- memset(ret, 0 , sizeof *ret);
ret->peer_key = &(ret->peer_pkeys[SSL_PKEY_RSA_ENC]);
ret->references = 1;
MemCheck_off();
ssl_comp_methods = sk_SSL_COMP_new(sk_comp_cmp);
if (ssl_comp_methods != NULL) {
- comp = (SSL_COMP *)malloc(sizeof(SSL_COMP));
+ comp = malloc(sizeof(SSL_COMP));
if (comp != NULL) {
comp->method = COMP_zlib();
if (comp->method &&
}
MemCheck_off();
- comp = (SSL_COMP *)malloc(sizeof(SSL_COMP));
+ comp = malloc(sizeof(SSL_COMP));
comp->id = id;
comp->method = cm;
load_builtin_compressions();
return (NULL);
}
- s = (SSL *)malloc(sizeof(SSL));
+ s = calloc(1, sizeof(SSL));
if (s == NULL)
goto err;
- memset(s, 0, sizeof(SSL));
#ifndef OPENSSL_NO_KRB5
s->kssl_ctx = kssl_ctx_new();
SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
goto err;
}
- ret = (SSL_CTX *)malloc(sizeof(SSL_CTX));
+ ret = calloc(1, sizeof(SSL_CTX));
if (ret == NULL)
goto err;
- memset(ret, 0, sizeof(SSL_CTX));
-
ret->method = meth;
ret->cert_store = NULL;
{
SSL_SESSION *ss;
- ss = (SSL_SESSION *)malloc(sizeof(SSL_SESSION));
+ ss = calloc(1, sizeof(SSL_SESSION));
if (ss == NULL) {
SSLerr(SSL_F_SSL_SESSION_NEW, ERR_R_MALLOC_FAILURE);
return (0);
}
- memset(ss, 0, sizeof(SSL_SESSION));
ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */
ss->references = 1;
#ifndef OPENSSL_NO_KRB5
if (s->kssl_ctx && !s->kssl_ctx->client_princ &&
session->krb5_client_princ_len > 0) {
- s->kssl_ctx->client_princ = (char *)malloc(session->krb5_client_princ_len + 1);
+ s->kssl_ctx->client_princ = malloc(session->krb5_client_princ_len + 1);
memcpy(s->kssl_ctx->client_princ, session->krb5_client_princ,
session->krb5_client_princ_len);
s->kssl_ctx->client_princ[session->krb5_client_princ_len] = '\0';
ssl3_cleanup_key_block(s);
- if ((p1 = (unsigned char *)malloc(num)) == NULL) {
+ if ((p1 = malloc(num)) == NULL) {
SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, ERR_R_MALLOC_FAILURE);
goto err;
}
s->s3->tmp.key_block_length = num;
s->s3->tmp.key_block = p1;
- if ((p2 = (unsigned char *)malloc(num)) == NULL) {
+ if ((p2 = malloc(num)) == NULL) {
SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!s->session->tlsext_tick)
return NULL;
memcpy(s->session->tlsext_tick,
- s->tlsext_session_ticket->data,
- ticklen);
+ s->tlsext_session_ticket->data, ticklen);
s->session->tlsext_ticklen = ticklen;
} else
ticklen = 0;
*al = TLS1_AD_UNRECOGNIZED_NAME;
return 0;
}
- if ((s->session->tlsext_hostname = malloc(len + 1)) == NULL) {
+ if ((s->session->tlsext_hostname =
+ malloc(len + 1)) == NULL) {
*al = TLS1_AD_INTERNAL_ERROR;
return 0;
}
s->session->tlsext_ecpointformatlist = NULL;
}
s->session->tlsext_ecpointformatlist_length = 0;
- if ((s->session->tlsext_ecpointformatlist = malloc(ecpointformatlist_length)) == NULL) {
+ if ((s->session->tlsext_ecpointformatlist =
+ malloc(ecpointformatlist_length)) == NULL) {
*al = TLS1_AD_INTERNAL_ERROR;
return 0;
}
return 0;
}
s->session->tlsext_ellipticcurvelist_length = 0;
- if ((s->session->tlsext_ellipticcurvelist = malloc(ellipticcurvelist_length)) == NULL) {
+ if ((s->session->tlsext_ellipticcurvelist =
+ malloc(ellipticcurvelist_length)) == NULL) {
*al = TLS1_AD_INTERNAL_ERROR;
return 0;
}
s->session->tlsext_ecpointformatlist_length = 0;
if (s->session->tlsext_ecpointformatlist != NULL)
free(s->session->tlsext_ecpointformatlist);
- if ((s->session->tlsext_ecpointformatlist = malloc(ecpointformatlist_length)) == NULL) {
+ if ((s->session->tlsext_ecpointformatlist =
+ malloc(ecpointformatlist_length)) == NULL) {
*al = TLS1_AD_INTERNAL_ERROR;
return 0;
}
{
CERT *ret;
- ret = (CERT *)malloc(sizeof(CERT));
+ ret = calloc(1, sizeof(CERT));
if (ret == NULL) {
SSLerr(SSL_F_SSL_CERT_NEW, ERR_R_MALLOC_FAILURE);
return (NULL);
}
- memset(ret, 0, sizeof(CERT));
-
ret->key = &(ret->pkeys[SSL_PKEY_RSA_ENC]);
ret->references = 1;
ssl_cert_set_default_md(ret);
CERT *ret;
int i;
- ret = (CERT *)malloc(sizeof(CERT));
+ ret = calloc(1, sizeof(CERT));
if (ret == NULL) {
SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE);
return (NULL);
}
- memset(ret, 0, sizeof(CERT));
-
ret->key = &ret->pkeys[cert->key - &cert->pkeys[0]];
/* or ret->key = ret->pkeys + (cert->key - cert->pkeys),
* if you find that more readable */
{
SESS_CERT *ret;
- ret = malloc(sizeof *ret);
+ ret = calloc(1, sizeof *ret);
if (ret == NULL) {
SSLerr(SSL_F_SSL_SESS_CERT_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
}
-
- memset(ret, 0 , sizeof *ret);
ret->peer_key = &(ret->peer_pkeys[SSL_PKEY_RSA_ENC]);
ret->references = 1;
MemCheck_off();
ssl_comp_methods = sk_SSL_COMP_new(sk_comp_cmp);
if (ssl_comp_methods != NULL) {
- comp = (SSL_COMP *)malloc(sizeof(SSL_COMP));
+ comp = malloc(sizeof(SSL_COMP));
if (comp != NULL) {
comp->method = COMP_zlib();
if (comp->method &&
}
MemCheck_off();
- comp = (SSL_COMP *)malloc(sizeof(SSL_COMP));
+ comp = malloc(sizeof(SSL_COMP));
comp->id = id;
comp->method = cm;
load_builtin_compressions();
return (NULL);
}
- s = (SSL *)malloc(sizeof(SSL));
+ s = calloc(1, sizeof(SSL));
if (s == NULL)
goto err;
- memset(s, 0, sizeof(SSL));
#ifndef OPENSSL_NO_KRB5
s->kssl_ctx = kssl_ctx_new();
SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
goto err;
}
- ret = (SSL_CTX *)malloc(sizeof(SSL_CTX));
+ ret = calloc(1, sizeof(SSL_CTX));
if (ret == NULL)
goto err;
- memset(ret, 0, sizeof(SSL_CTX));
-
ret->method = meth;
ret->cert_store = NULL;
{
SSL_SESSION *ss;
- ss = (SSL_SESSION *)malloc(sizeof(SSL_SESSION));
+ ss = calloc(1, sizeof(SSL_SESSION));
if (ss == NULL) {
SSLerr(SSL_F_SSL_SESSION_NEW, ERR_R_MALLOC_FAILURE);
return (0);
}
- memset(ss, 0, sizeof(SSL_SESSION));
ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */
ss->references = 1;
#ifndef OPENSSL_NO_KRB5
if (s->kssl_ctx && !s->kssl_ctx->client_princ &&
session->krb5_client_princ_len > 0) {
- s->kssl_ctx->client_princ = (char *)malloc(session->krb5_client_princ_len + 1);
+ s->kssl_ctx->client_princ = malloc(session->krb5_client_princ_len + 1);
memcpy(s->kssl_ctx->client_princ, session->krb5_client_princ,
session->krb5_client_princ_len);
s->kssl_ctx->client_princ[session->krb5_client_princ_len] = '\0';
ssl3_cleanup_key_block(s);
- if ((p1 = (unsigned char *)malloc(num)) == NULL) {
+ if ((p1 = malloc(num)) == NULL) {
SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, ERR_R_MALLOC_FAILURE);
goto err;
}
s->s3->tmp.key_block_length = num;
s->s3->tmp.key_block = p1;
- if ((p2 = (unsigned char *)malloc(num)) == NULL) {
+ if ((p2 = malloc(num)) == NULL) {
SSLerr(SSL_F_TLS1_SETUP_KEY_BLOCK, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!s->session->tlsext_tick)
return NULL;
memcpy(s->session->tlsext_tick,
- s->tlsext_session_ticket->data,
- ticklen);
+ s->tlsext_session_ticket->data, ticklen);
s->session->tlsext_ticklen = ticklen;
} else
ticklen = 0;
*al = TLS1_AD_UNRECOGNIZED_NAME;
return 0;
}
- if ((s->session->tlsext_hostname = malloc(len + 1)) == NULL) {
+ if ((s->session->tlsext_hostname =
+ malloc(len + 1)) == NULL) {
*al = TLS1_AD_INTERNAL_ERROR;
return 0;
}
s->session->tlsext_ecpointformatlist = NULL;
}
s->session->tlsext_ecpointformatlist_length = 0;
- if ((s->session->tlsext_ecpointformatlist = malloc(ecpointformatlist_length)) == NULL) {
+ if ((s->session->tlsext_ecpointformatlist =
+ malloc(ecpointformatlist_length)) == NULL) {
*al = TLS1_AD_INTERNAL_ERROR;
return 0;
}
return 0;
}
s->session->tlsext_ellipticcurvelist_length = 0;
- if ((s->session->tlsext_ellipticcurvelist = malloc(ellipticcurvelist_length)) == NULL) {
+ if ((s->session->tlsext_ellipticcurvelist =
+ malloc(ellipticcurvelist_length)) == NULL) {
*al = TLS1_AD_INTERNAL_ERROR;
return 0;
}
s->session->tlsext_ecpointformatlist_length = 0;
if (s->session->tlsext_ecpointformatlist != NULL)
free(s->session->tlsext_ecpointformatlist);
- if ((s->session->tlsext_ecpointformatlist = malloc(ecpointformatlist_length)) == NULL) {
+ if ((s->session->tlsext_ecpointformatlist =
+ malloc(ecpointformatlist_length)) == NULL) {
*al = TLS1_AD_INTERNAL_ERROR;
return 0;
}