diff options
author | Rich Salz <rsalz@akamai.com> | 2015-05-04 18:00:15 -0400 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2015-05-05 22:18:59 -0400 |
commit | 16f8d4ebf0fd4847fa83d9c61f4150273cb4f533 (patch) | |
tree | 3c30094cad38433c24008c30efe3d93cf38d8ae9 /ssl | |
parent | 12048657a91b12e499d03ec9ff406b42aba67366 (diff) |
memset, memcpy, sizeof consistency fixes
Just as with the OPENSSL_malloc calls, consistently use sizeof(*ptr)
for memset and memcpy. Remove needless casts for those functions.
For memset, replace alternative forms of zero with 0.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'ssl')
-rw-r--r-- | ssl/bio_ssl.c | 2 | ||||
-rw-r--r-- | ssl/d1_both.c | 8 | ||||
-rw-r--r-- | ssl/d1_lib.c | 12 | ||||
-rw-r--r-- | ssl/d1_msg.c | 2 | ||||
-rw-r--r-- | ssl/kssl.c | 8 | ||||
-rw-r--r-- | ssl/record/rec_layer_d1.c | 13 | ||||
-rw-r--r-- | ssl/record/rec_layer_s3.c | 2 | ||||
-rw-r--r-- | ssl/s3_clnt.c | 4 | ||||
-rw-r--r-- | ssl/s3_enc.c | 5 | ||||
-rw-r--r-- | ssl/s3_srvr.c | 5 | ||||
-rw-r--r-- | ssl/ssl_cert.c | 11 | ||||
-rw-r--r-- | ssl/ssl_ciph.c | 4 | ||||
-rw-r--r-- | ssl/ssl_lib.c | 6 | ||||
-rw-r--r-- | ssl/ssl_sess.c | 2 | ||||
-rw-r--r-- | ssl/t1_ext.c | 2 |
15 files changed, 41 insertions, 45 deletions
diff --git a/ssl/bio_ssl.c b/ssl/bio_ssl.c index 18e70747b3..aa6d623191 100644 --- a/ssl/bio_ssl.c +++ b/ssl/bio_ssl.c @@ -107,7 +107,7 @@ static int ssl_new(BIO *bi) BIOerr(BIO_F_SSL_NEW, ERR_R_MALLOC_FAILURE); return (0); } - memset(bs, 0, sizeof(BIO_SSL)); + memset(bs, 0, sizeof(*bs)); bi->init = 0; bi->ptr = (char *)bs; bi->flags = 0; diff --git a/ssl/d1_both.c b/ssl/d1_both.c index 65a3a18bc4..05b8f9e08a 100644 --- a/ssl/d1_both.c +++ b/ssl/d1_both.c @@ -467,7 +467,7 @@ long dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) } msg_hdr = &s->d1->r_msg_hdr; - memset(msg_hdr, 0x00, sizeof(struct hm_header_st)); + memset(msg_hdr, 0, sizeof(*msg_hdr)); again: i = dtls1_get_message_fragment(s, st1, stn, max, ok); @@ -497,7 +497,7 @@ long dtls1_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, p, msg_len, s, s->msg_callback_arg); - memset(msg_hdr, 0x00, sizeof(struct hm_header_st)); + memset(msg_hdr, 0, sizeof(*msg_hdr)); /* Don't change sequence numbers while listening */ if (!s->d1->listen) @@ -1289,7 +1289,7 @@ unsigned int dtls1_min_mtu(SSL *s) void dtls1_get_message_header(unsigned char *data, struct hm_header_st *msg_hdr) { - memset(msg_hdr, 0x00, sizeof(struct hm_header_st)); + memset(msg_hdr, 0, sizeof(*msg_hdr)); msg_hdr->type = *(data++); n2l3(data, msg_hdr->msg_len); @@ -1300,7 +1300,7 @@ dtls1_get_message_header(unsigned char *data, struct hm_header_st *msg_hdr) void dtls1_get_ccs_header(unsigned char *data, struct ccs_header_st *ccs_hdr) { - memset(ccs_hdr, 0x00, sizeof(struct ccs_header_st)); + memset(ccs_hdr, 0, sizeof(*ccs_hdr)); ccs_hdr->type = *(data++); } diff --git a/ssl/d1_lib.c b/ssl/d1_lib.c index 3441fc56e0..c0ed8fb852 100644 --- a/ssl/d1_lib.c +++ b/ssl/d1_lib.c @@ -215,7 +215,7 @@ void dtls1_clear(SSL *s) dtls1_clear_queues(s); - memset(s->d1, 0, sizeof(*(s->d1))); + memset(s->d1, 0, sizeof(*s->d1)); if (s->server) { s->d1->cookie_len = sizeof(s->d1->cookie); @@ -324,7 +324,7 @@ void dtls1_start_timer(SSL *s) #ifndef OPENSSL_NO_SCTP /* Disable timer for SCTP */ if (BIO_dgram_is_sctp(SSL_get_wbio(s))) { - memset(&(s->d1->next_timeout), 0, sizeof(struct timeval)); + memset(&s->d1->next_timeout, 0, sizeof(s->d1->next_timeout)); return; } #endif @@ -359,7 +359,7 @@ struct timeval *dtls1_get_timeout(SSL *s, struct timeval *timeleft) if (s->d1->next_timeout.tv_sec < timenow.tv_sec || (s->d1->next_timeout.tv_sec == timenow.tv_sec && s->d1->next_timeout.tv_usec <= timenow.tv_usec)) { - memset(timeleft, 0, sizeof(struct timeval)); + memset(timeleft, 0, sizeof(*timeleft)); return timeleft; } @@ -377,7 +377,7 @@ struct timeval *dtls1_get_timeout(SSL *s, struct timeval *timeleft) * because of small devergences with socket timeouts. */ if (timeleft->tv_sec == 0 && timeleft->tv_usec < 15000) { - memset(timeleft, 0, sizeof(struct timeval)); + memset(timeleft, 0, sizeof(*timeleft)); } return timeleft; @@ -412,8 +412,8 @@ void dtls1_double_timeout(SSL *s) void dtls1_stop_timer(SSL *s) { /* Reset everything */ - memset(&(s->d1->timeout), 0, sizeof(struct dtls1_timeout_st)); - memset(&(s->d1->next_timeout), 0, sizeof(struct timeval)); + memset(&s->d1->timeout, 0, sizeof(s->d1->timeout)); + memset(&s->d1->next_timeout, 0, sizeof(s->d1->next_timeout)); s->d1->timeout_duration = 1; BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0, &(s->d1->next_timeout)); diff --git a/ssl/d1_msg.c b/ssl/d1_msg.c index f71b1cca16..13bda46922 100644 --- a/ssl/d1_msg.c +++ b/ssl/d1_msg.c @@ -161,7 +161,7 @@ int dtls1_dispatch_alert(SSL *s) s->s3->alert_dispatch = 0; - memset(buf, 0x00, sizeof(buf)); + memset(buf, 0, sizeof(buf)); *ptr++ = s->s3->send_alert[0]; *ptr++ = s->s3->send_alert[1]; diff --git a/ssl/kssl.c b/ssl/kssl.c index ce43529161..d781042247 100644 --- a/ssl/kssl.c +++ b/ssl/kssl.c @@ -1048,7 +1048,7 @@ krb5_error_code kssl_cget_tkt( /* UPDATE */ KSSL_CTX *kssl_ctx, krb5_data krb5_app_req; kssl_err_set(kssl_err, 0, ""); - memset((char *)&krb5creds, 0, sizeof(krb5creds)); + memset(&krb5creds, 0, sizeof(krb5creds)); if (!kssl_ctx) { kssl_err_set(kssl_err, SSL_R_KRB5_S_INIT, "No kssl_ctx defined.\n"); @@ -1797,7 +1797,7 @@ int kssl_tgt_is_available(KSSL_CTX *kssl_ctx) krb5_creds krb5creds, *krb5credsp = NULL; int rc = 0; - memset((char *)&krb5creds, 0, sizeof(krb5creds)); + memset(&krb5creds, 0, sizeof(krb5creds)); if (!kssl_ctx) return (0); @@ -2072,7 +2072,7 @@ krb5_error_code kssl_check_authent( } # endif enc = kssl_map_enc(enctype); - memset(iv, 0, sizeof iv); /* per RFC 1510 */ + memset(iv, 0, sizeof(iv)); /* per RFC 1510 */ if (enc == NULL) { /* @@ -2126,7 +2126,7 @@ krb5_error_code kssl_check_authent( goto err; } - memset(&tm_time, 0, sizeof(struct tm)); + memset(&tm_time, 0, sizeof(tm_tmime)); if (k_gmtime(auth->ctime, &tm_time) && ((tr = mktime(&tm_time)) != (time_t)(-1))) { now = time(&now); diff --git a/ssl/record/rec_layer_d1.c b/ssl/record/rec_layer_d1.c index 2635894ed3..45324ecb15 100644 --- a/ssl/record/rec_layer_d1.c +++ b/ssl/record/rec_layer_d1.c @@ -286,8 +286,8 @@ int dtls1_buffer_record(SSL *s, record_pqueue *queue, unsigned char *priority) s->rlayer.packet = NULL; s->rlayer.packet_length = 0; - memset(&s->rlayer.rbuf, 0, sizeof(SSL3_BUFFER)); - memset(&s->rlayer.rrec, 0, sizeof(SSL3_RECORD)); + memset(&s->rlayer.rbuf, 0, sizeof(s->rlayer.rbuf)); + memset(&s->rlayer.rrec, 0, sizeof(s->rlayer.rrec)); if (!ssl3_setup_buffers(s)) { SSLerr(SSL_F_DTLS1_BUFFER_RECORD, ERR_R_INTERNAL_ERROR); @@ -1298,9 +1298,10 @@ void dtls1_reset_seq_numbers(SSL *s, int rw) if (rw & SSL3_CC_READ) { seq = s->rlayer.read_sequence; s->rlayer.d->r_epoch++; - memcpy(&(s->rlayer.d->bitmap), &(s->rlayer.d->next_bitmap), - sizeof(DTLS1_BITMAP)); - memset(&(s->rlayer.d->next_bitmap), 0x00, sizeof(DTLS1_BITMAP)); + memcpy(&s->rlayer.d->bitmap, &s->rlayer.d->next_bitmap, + sizeof(s->rlayer.d->bitmap)); + memset(&s->rlayer.d->next_bitmap, 0, + sizeof(s->rlayer.d->next_bitmap)); } else { seq = s->rlayer.write_sequence; memcpy(s->rlayer.d->last_write_sequence, seq, @@ -1308,5 +1309,5 @@ void dtls1_reset_seq_numbers(SSL *s, int rw) s->rlayer.d->w_epoch++; } - memset(seq, 0x00, seq_bytes); + memset(seq, 0, seq_bytes); } diff --git a/ssl/record/rec_layer_s3.c b/ssl/record/rec_layer_s3.c index 0ed82f727e..eccb5176ba 100644 --- a/ssl/record/rec_layer_s3.c +++ b/ssl/record/rec_layer_s3.c @@ -155,7 +155,7 @@ void RECORD_LAYER_clear(RECORD_LAYER *rl) rlen = SSL3_BUFFER_get_len(&rl->rbuf); wp = SSL3_BUFFER_get_buf(&rl->wbuf); wlen = SSL3_BUFFER_get_len(&rl->wbuf); - memset(rl, 0, sizeof (RECORD_LAYER)); + memset(rl, 0, sizeof(*rl)); SSL3_BUFFER_set_buf(&rl->rbuf, rp); SSL3_BUFFER_set_len(&rl->rbuf, rlen); SSL3_BUFFER_set_buf(&rl->wbuf, wp); diff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c index f936fa3535..ea4503fbcb 100644 --- a/ssl/s3_clnt.c +++ b/ssl/s3_clnt.c @@ -2518,7 +2518,7 @@ int ssl3_send_client_key_exchange(SSL *s) * EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv); */ - memset(iv, 0, sizeof iv); /* per RFC 1510 */ + memset(iv, 0, sizeof(iv)); /* per RFC 1510 */ EVP_EncryptInit_ex(&ciph_ctx, enc, NULL, kssl_ctx->key, iv); EVP_EncryptUpdate(&ciph_ctx, epms, &outl, pms, pmslen); EVP_EncryptFinal_ex(&ciph_ctx, &(epms[outl]), &padl); @@ -2788,7 +2788,7 @@ int ssl3_send_client_key_exchange(SSL *s) /* Encoded point will be copied here */ p += 1; /* copy the point */ - memcpy((unsigned char *)p, encodedPoint, n); + memcpy(p, encodedPoint, n); /* increment n to account for length field */ n += 1; } diff --git a/ssl/s3_enc.c b/ssl/s3_enc.c index d968a1c04b..ea9042b165 100644 --- a/ssl/s3_enc.c +++ b/ssl/s3_enc.c @@ -519,12 +519,13 @@ int ssl3_digest_cached_records(SSL *s) /* Allocate handshake_dgst array */ ssl3_free_digest_list(s); s->s3->handshake_dgst = - OPENSSL_malloc(SSL_MAX_DIGEST * sizeof(EVP_MD_CTX *)); + OPENSSL_malloc(sizeof(*s->s3->handshake_dgst) * SSL_MAX_DIGEST); if (s->s3->handshake_dgst == NULL) { SSLerr(SSL_F_SSL3_DIGEST_CACHED_RECORDS, ERR_R_MALLOC_FAILURE); return 0; } - memset(s->s3->handshake_dgst, 0, SSL_MAX_DIGEST * sizeof(EVP_MD_CTX *)); + memset(s->s3->handshake_dgst, 0, + sizeof(*s->s3->handshake_dgst) * SSL_MAX_DIGEST); 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); diff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c index e6884f3fb1..ec94882aca 100644 --- a/ssl/s3_srvr.c +++ b/ssl/s3_srvr.c @@ -1935,8 +1935,7 @@ int ssl3_send_server_key_exchange(SSL *s) p += 1; *p = encodedlen; p += 1; - memcpy((unsigned char *)p, - (unsigned char *)encodedPoint, encodedlen); + memcpy(p, encodedPoint, encodedlen); OPENSSL_free(encodedPoint); encodedPoint = NULL; p += encodedlen; @@ -2509,7 +2508,7 @@ int ssl3_get_client_key_exchange(SSL *s) if (enc == NULL) goto err; - memset(iv, 0, sizeof iv); /* per RFC 1510 */ + memset(iv, 0, sizeof(iv)); /* per RFC 1510 */ if (!EVP_DecryptInit_ex(&ciph_ctx, enc, NULL, kssl_ctx->key, iv)) { SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE, diff --git a/ssl/ssl_cert.c b/ssl/ssl_cert.c index c7a2aa9957..38e7b822e5 100644 --- a/ssl/ssl_cert.c +++ b/ssl/ssl_cert.c @@ -188,7 +188,7 @@ CERT *ssl_cert_new(void) SSLerr(SSL_F_SSL_CERT_NEW, ERR_R_MALLOC_FAILURE); return (NULL); } - memset(ret, 0, sizeof(CERT)); + memset(ret, 0, sizeof(*ret)); ret->key = &(ret->pkeys[SSL_PKEY_RSA_ENC]); ret->references = 1; @@ -209,14 +209,9 @@ CERT *ssl_cert_dup(CERT *cert) 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 - */ + memset(ret, 0, sizeof(*ret)); + ret->key = &ret->pkeys[cert->key - cert->pkeys]; ret->valid = cert->valid; ret->mask_k = cert->mask_k; ret->mask_a = cert->mask_a; diff --git a/ssl/ssl_ciph.c b/ssl/ssl_ciph.c index 0ddb56bb39..a81ab8555f 100644 --- a/ssl/ssl_ciph.c +++ b/ssl/ssl_ciph.c @@ -1063,12 +1063,12 @@ static int ssl_cipher_strength_sort(CIPHER_ORDER **head_p, curr = curr->next; } - number_uses = OPENSSL_malloc((max_strength_bits + 1) * sizeof(int)); + number_uses = OPENSSL_malloc(sizeof(int) * (max_strength_bits + 1)); if (!number_uses) { SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT, ERR_R_MALLOC_FAILURE); return (0); } - memset(number_uses, 0, (max_strength_bits + 1) * sizeof(int)); + memset(number_uses, 0, sizeof(int) * (max_strength_bits + 1)); /* * Now find the strength_bits values actually used diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 56d7e6c55a..0a2c04e741 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -275,7 +275,7 @@ SSL *SSL_new(SSL_CTX *ctx) s = OPENSSL_malloc(sizeof(*s)); if (s == NULL) goto err; - memset(s, 0, sizeof(SSL)); + memset(s, 0, sizeof(*s)); RECORD_LAYER_init(&s->rlayer, s); @@ -1848,7 +1848,7 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth) if (ret == NULL) goto err; - memset(ret, 0, sizeof(SSL_CTX)); + memset(ret, 0, sizeof(*ret)); ret->method = meth; @@ -1866,7 +1866,7 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth) ret->get_session_cb = 0; ret->generate_session_id = 0; - memset((char *)&ret->stats, 0, sizeof(ret->stats)); + memset(&ret->stats, 0, sizeof(ret->stats)); ret->references = 1; ret->quiet_shutdown = 0; diff --git a/ssl/ssl_sess.c b/ssl/ssl_sess.c index b592da4dae..4e73f047e0 100644 --- a/ssl/ssl_sess.c +++ b/ssl/ssl_sess.c @@ -198,7 +198,7 @@ SSL_SESSION *SSL_SESSION_new(void) SSLerr(SSL_F_SSL_SESSION_NEW, ERR_R_MALLOC_FAILURE); return (0); } - memset(ss, 0, sizeof(SSL_SESSION)); + memset(ss, 0, sizeof(*ss)); ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */ ss->references = 1; diff --git a/ssl/t1_ext.c b/ssl/t1_ext.c index 193cae886a..f1092ac93d 100644 --- a/ssl/t1_ext.c +++ b/ssl/t1_ext.c @@ -232,7 +232,7 @@ static int custom_ext_meth_add(custom_ext_methods *exts, } meth = exts->meths + exts->meths_count; - memset(meth, 0, sizeof(custom_ext_method)); + memset(meth, 0, sizeof(*meth)); meth->parse_cb = parse_cb; meth->add_cb = add_cb; meth->free_cb = free_cb; |