Ver código fonte

Don't cast |OPENSSL_malloc|/|OPENSSL_realloc| result.

C has implicit conversion of |void *| to other pointer types so these
casts are unnecessary. Clean them up to make the code easier to read
and to make it easier to find dangerous casts.

Change-Id: I26988a672e8ed4d69c75cfbb284413999b475464
Reviewed-on: https://boringssl-review.googlesource.com/7102
Reviewed-by: David Benjamin <davidben@google.com>
kris/onging/CECPQ3_patch15
Brian Smith 8 anos atrás
committed by David Benjamin
pai
commit
5ba06897be
20 arquivos alterados com 29 adições e 33 exclusões
  1. +3
    -3
      crypto/bio/buffer.c
  2. +1
    -1
      crypto/bn/bn.c
  3. +3
    -4
      crypto/bn/convert.c
  4. +1
    -1
      crypto/bn/exponentiation.c
  5. +1
    -1
      crypto/dh/dh.c
  6. +1
    -1
      crypto/dsa/dsa.c
  7. +1
    -1
      crypto/ec/ec_key.c
  8. +1
    -1
      crypto/evp/p_dsa_asn1.c
  9. +1
    -1
      crypto/evp/p_ec_asn1.c
  10. +1
    -1
      crypto/evp/p_rsa_asn1.c
  11. +1
    -1
      crypto/modes/gcm.c
  12. +1
    -1
      crypto/rsa/rsa.c
  13. +2
    -2
      ssl/pqueue/pqueue.c
  14. +1
    -1
      ssl/ssl_aead_ctx.c
  15. +2
    -2
      ssl/ssl_cert.c
  16. +1
    -1
      ssl/ssl_cipher.c
  17. +2
    -2
      ssl/ssl_lib.c
  18. +1
    -1
      ssl/ssl_session.c
  19. +1
    -1
      ssl/t1_enc.c
  20. +3
    -6
      ssl/t1_lib.c

+ 3
- 3
crypto/bio/buffer.c Ver arquivo

@@ -100,7 +100,7 @@ static int buffer_new(BIO *bio) {
if (ctx->ibuf == NULL) {
goto err1;
}
ctx->obuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
ctx->obuf = OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
if (ctx->obuf == NULL) {
goto err2;
}
@@ -340,13 +340,13 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr) {
p1 = ctx->ibuf;
p2 = ctx->obuf;
if (ibs > DEFAULT_BUFFER_SIZE && ibs != ctx->ibuf_size) {
p1 = (char *)OPENSSL_malloc(ibs);
p1 = OPENSSL_malloc(ibs);
if (p1 == NULL) {
goto malloc_error;
}
}
if (obs > DEFAULT_BUFFER_SIZE && obs != ctx->obuf_size) {
p2 = (char *)OPENSSL_malloc(obs);
p2 = OPENSSL_malloc(obs);
if (p2 == NULL) {
if (p1 != ctx->ibuf) {
OPENSSL_free(p1);


+ 1
- 1
crypto/bn/bn.c Ver arquivo

@@ -295,7 +295,7 @@ BIGNUM *bn_wexpand(BIGNUM *bn, size_t words) {
return NULL;
}

a = (BN_ULONG *)OPENSSL_malloc(sizeof(BN_ULONG) * words);
a = OPENSSL_malloc(sizeof(BN_ULONG) * words);
if (a == NULL) {
OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
return NULL;


+ 3
- 4
crypto/bn/convert.c Ver arquivo

@@ -208,7 +208,7 @@ char *BN_bn2hex(const BIGNUM *bn) {
char *buf;
char *p;

buf = (char *)OPENSSL_malloc(bn->top * BN_BYTES * 2 + 2);
buf = OPENSSL_malloc(bn->top * BN_BYTES * 2 + 2);
if (buf == NULL) {
OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
return NULL;
@@ -385,9 +385,8 @@ char *BN_bn2dec(const BIGNUM *a) {
*/
i = BN_num_bits(a) * 3;
num = i / 10 + i / 1000 + 1 + 1;
bn_data =
(BN_ULONG *)OPENSSL_malloc((num / BN_DEC_NUM + 1) * sizeof(BN_ULONG));
buf = (char *)OPENSSL_malloc(num + 3);
bn_data = OPENSSL_malloc((num / BN_DEC_NUM + 1) * sizeof(BN_ULONG));
buf = OPENSSL_malloc(num + 3);
if ((buf == NULL) || (bn_data == NULL)) {
OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
goto err;


+ 1
- 1
crypto/bn/exponentiation.c Ver arquivo

@@ -954,7 +954,7 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
} else
#endif
{
if ((powerbufFree = (unsigned char *)OPENSSL_malloc(
if ((powerbufFree = OPENSSL_malloc(
powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL) {
goto err;
}


+ 1
- 1
crypto/dh/dh.c Ver arquivo

@@ -74,7 +74,7 @@
static CRYPTO_EX_DATA_CLASS g_ex_data_class = CRYPTO_EX_DATA_CLASS_INIT;

DH *DH_new(void) {
DH *dh = (DH *)OPENSSL_malloc(sizeof(DH));
DH *dh = OPENSSL_malloc(sizeof(DH));
if (dh == NULL) {
OPENSSL_PUT_ERROR(DH, ERR_R_MALLOC_FAILURE);
return NULL;


+ 1
- 1
crypto/dsa/dsa.c Ver arquivo

@@ -86,7 +86,7 @@
static CRYPTO_EX_DATA_CLASS g_ex_data_class = CRYPTO_EX_DATA_CLASS_INIT;

DSA *DSA_new(void) {
DSA *dsa = (DSA *)OPENSSL_malloc(sizeof(DSA));
DSA *dsa = OPENSSL_malloc(sizeof(DSA));
if (dsa == NULL) {
OPENSSL_PUT_ERROR(DSA, ERR_R_MALLOC_FAILURE);
return NULL;


+ 1
- 1
crypto/ec/ec_key.c Ver arquivo

@@ -85,7 +85,7 @@ static CRYPTO_EX_DATA_CLASS g_ex_data_class = CRYPTO_EX_DATA_CLASS_INIT;
EC_KEY *EC_KEY_new(void) { return EC_KEY_new_method(NULL); }

EC_KEY *EC_KEY_new_method(const ENGINE *engine) {
EC_KEY *ret = (EC_KEY *)OPENSSL_malloc(sizeof(EC_KEY));
EC_KEY *ret = OPENSSL_malloc(sizeof(EC_KEY));
if (ret == NULL) {
OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
return NULL;


+ 1
- 1
crypto/evp/p_dsa_asn1.c Ver arquivo

@@ -436,7 +436,7 @@ static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) {
update_buflen(priv_key, &buf_len);
update_buflen(pub_key, &buf_len);

m = (uint8_t *)OPENSSL_malloc(buf_len + 10);
m = OPENSSL_malloc(buf_len + 10);
if (m == NULL) {
OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
goto err;


+ 1
- 1
crypto/evp/p_ec_asn1.c Ver arquivo

@@ -279,7 +279,7 @@ static int eckey_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey) {
OPENSSL_PUT_ERROR(EVP, ERR_R_EC_LIB);
return 0;
}
ep = (uint8_t *)OPENSSL_malloc(eplen);
ep = OPENSSL_malloc(eplen);
if (!ep) {
EC_KEY_set_enc_flags(ec_key, old_flags);
OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);


+ 1
- 1
crypto/evp/p_rsa_asn1.c Ver arquivo

@@ -216,7 +216,7 @@ static int do_rsa_print(BIO *out, const RSA *rsa, int off,
}
}

m = (uint8_t *)OPENSSL_malloc(buf_len + 10);
m = OPENSSL_malloc(buf_len + 10);
if (m == NULL) {
OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
goto err;


+ 1
- 1
crypto/modes/gcm.c Ver arquivo

@@ -408,7 +408,7 @@ void gcm_ghash_neon(uint64_t Xi[2], const u128 Htable[16], const uint8_t *inp,
GCM128_CONTEXT *CRYPTO_gcm128_new(const void *key, block128_f block) {
GCM128_CONTEXT *ret;

ret = (GCM128_CONTEXT *)OPENSSL_malloc(sizeof(GCM128_CONTEXT));
ret = OPENSSL_malloc(sizeof(GCM128_CONTEXT));
if (ret != NULL) {
CRYPTO_gcm128_init(ret, key, block);
}


+ 1
- 1
crypto/rsa/rsa.c Ver arquivo

@@ -76,7 +76,7 @@ static CRYPTO_EX_DATA_CLASS g_ex_data_class = CRYPTO_EX_DATA_CLASS_INIT;
RSA *RSA_new(void) { return RSA_new_method(NULL); }

RSA *RSA_new_method(const ENGINE *engine) {
RSA *rsa = (RSA *)OPENSSL_malloc(sizeof(RSA));
RSA *rsa = OPENSSL_malloc(sizeof(RSA));
if (rsa == NULL) {
OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
return NULL;


+ 2
- 2
ssl/pqueue/pqueue.c Ver arquivo

@@ -69,7 +69,7 @@ typedef struct _pqueue {


pitem *pitem_new(uint8_t prio64be[8], void *data) {
pitem *item = (pitem *)OPENSSL_malloc(sizeof(pitem));
pitem *item = OPENSSL_malloc(sizeof(pitem));
if (item == NULL) {
return NULL;
}
@@ -91,7 +91,7 @@ void pitem_free(pitem *item) {
}

pqueue pqueue_new(void) {
pqueue_s *pq = (pqueue_s *)OPENSSL_malloc(sizeof(pqueue_s));
pqueue_s *pq = OPENSSL_malloc(sizeof(pqueue_s));
if (pq == NULL) {
return NULL;
}


+ 1
- 1
ssl/ssl_aead_ctx.c Ver arquivo

@@ -56,7 +56,7 @@ SSL_AEAD_CTX *SSL_AEAD_CTX_new(enum evp_aead_direction_t direction,
enc_key_len += fixed_iv_len;
}

SSL_AEAD_CTX *aead_ctx = (SSL_AEAD_CTX *)OPENSSL_malloc(sizeof(SSL_AEAD_CTX));
SSL_AEAD_CTX *aead_ctx = OPENSSL_malloc(sizeof(SSL_AEAD_CTX));
if (aead_ctx == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return NULL;


+ 2
- 2
ssl/ssl_cert.c Ver arquivo

@@ -139,7 +139,7 @@ int SSL_get_ex_data_X509_STORE_CTX_idx(void) {
}

CERT *ssl_cert_new(void) {
CERT *ret = (CERT *)OPENSSL_malloc(sizeof(CERT));
CERT *ret = OPENSSL_malloc(sizeof(CERT));
if (ret == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return NULL;
@@ -150,7 +150,7 @@ CERT *ssl_cert_new(void) {
}

CERT *ssl_cert_dup(CERT *cert) {
CERT *ret = (CERT *)OPENSSL_malloc(sizeof(CERT));
CERT *ret = OPENSSL_malloc(sizeof(CERT));
if (ret == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return NULL;


+ 1
- 1
ssl/ssl_cipher.c Ver arquivo

@@ -1392,7 +1392,7 @@ ssl_create_cipher_list(const SSL_PROTOCOL_METHOD *ssl_method,
/* Now we have to collect the available ciphers from the compiled in ciphers.
* We cannot get more than the number compiled in, so it is used for
* allocation. */
co_list = (CIPHER_ORDER *)OPENSSL_malloc(sizeof(CIPHER_ORDER) * kCiphersLen);
co_list = OPENSSL_malloc(sizeof(CIPHER_ORDER) * kCiphersLen);
if (co_list == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return NULL;


+ 2
- 2
ssl/ssl_lib.c Ver arquivo

@@ -221,7 +221,7 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *method) {
goto err;
}

ret = (SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX));
ret = OPENSSL_malloc(sizeof(SSL_CTX));
if (ret == NULL) {
goto err;
}
@@ -353,7 +353,7 @@ SSL *SSL_new(SSL_CTX *ctx) {
return NULL;
}

SSL *ssl = (SSL *)OPENSSL_malloc(sizeof(SSL));
SSL *ssl = OPENSSL_malloc(sizeof(SSL));
if (ssl == NULL) {
goto err;
}


+ 1
- 1
ssl/ssl_session.c Ver arquivo

@@ -161,7 +161,7 @@ static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *session);
static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *session, int lock);

SSL_SESSION *SSL_SESSION_new(void) {
SSL_SESSION *session = (SSL_SESSION *)OPENSSL_malloc(sizeof(SSL_SESSION));
SSL_SESSION *session = OPENSSL_malloc(sizeof(SSL_SESSION));
if (session == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return 0;


+ 1
- 1
ssl/t1_enc.c Ver arquivo

@@ -373,7 +373,7 @@ int tls1_setup_key_block(SSL *ssl) {

ssl3_cleanup_key_block(ssl);

uint8_t *keyblock = (uint8_t *)OPENSSL_malloc(key_block_len);
uint8_t *keyblock = OPENSSL_malloc(key_block_len);
if (keyblock == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return 0;


+ 3
- 6
ssl/t1_lib.c Ver arquivo

@@ -169,8 +169,7 @@ static int tls1_check_duplicate_extensions(const CBS *cbs) {
return 1;
}

extension_types =
(uint16_t *)OPENSSL_malloc(sizeof(uint16_t) * num_extensions);
extension_types = OPENSSL_malloc(sizeof(uint16_t) * num_extensions);
if (extension_types == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
goto done;
@@ -377,7 +376,7 @@ int tls1_set_curves(uint16_t **out_curve_ids, size_t *out_curve_ids_len,
uint16_t *curve_ids;
size_t i;

curve_ids = (uint16_t *)OPENSSL_malloc(ncurves * sizeof(uint16_t));
curve_ids = OPENSSL_malloc(ncurves * sizeof(uint16_t));
if (curve_ids == NULL) {
return 0;
}
@@ -1905,9 +1904,7 @@ static int ext_ec_curves_parse_clienthello(SSL *ssl, uint8_t *out_alert,
return 0;
}

ssl->s3->tmp.peer_ellipticcurvelist =
(uint16_t *)OPENSSL_malloc(CBS_len(&elliptic_curve_list));

ssl->s3->tmp.peer_ellipticcurvelist = OPENSSL_malloc(CBS_len(&elliptic_curve_list));
if (ssl->s3->tmp.peer_ellipticcurvelist == NULL) {
*out_alert = SSL_AD_INTERNAL_ERROR;
return 0;


Carregando…
Cancelar
Salvar