Convert some malloc + memcpys into BUF_memdup. Slightly tidier. Change-Id: Ib3cb4dc262c88087bd56b446a6f7a05d1e57ade6 Reviewed-on: https://boringssl-review.googlesource.com/1345 Reviewed-by: Adam Langley <agl@google.com>
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 0acf3d3..2e49302 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c
@@ -373,12 +373,11 @@ if (s->ctx->alpn_client_proto_list) { - s->alpn_client_proto_list = - OPENSSL_malloc(s->ctx->alpn_client_proto_list_len); + s->alpn_client_proto_list = BUF_memdup( + s->ctx->alpn_client_proto_list, + s->ctx->alpn_client_proto_list_len); if (s->alpn_client_proto_list == NULL) goto err; - memcpy(s->alpn_client_proto_list, s->ctx->alpn_client_proto_list, - s->ctx->alpn_client_proto_list_len); s->alpn_client_proto_list_len = s->ctx->alpn_client_proto_list_len; } @@ -551,10 +550,9 @@ ret->ciphers = sk_SSL_CIPHER_dup(cipher_list->ciphers); if (!ret->ciphers) goto err; - ret->in_group_flags = OPENSSL_malloc(n); + ret->in_group_flags = BUF_memdup(cipher_list->in_group_flags, n); if (!ret->in_group_flags) goto err; - memcpy(ret->in_group_flags, cipher_list->in_group_flags, n); return ret; err: @@ -1802,10 +1800,9 @@ if (ctx->alpn_client_proto_list) OPENSSL_free(ctx->alpn_client_proto_list); - ctx->alpn_client_proto_list = OPENSSL_malloc(protos_len); + ctx->alpn_client_proto_list = BUF_memdup(protos, protos_len); if (!ctx->alpn_client_proto_list) return 1; - memcpy(ctx->alpn_client_proto_list, protos, protos_len); ctx->alpn_client_proto_list_len = protos_len; return 0; @@ -1822,10 +1819,9 @@ if (ssl->alpn_client_proto_list) OPENSSL_free(ssl->alpn_client_proto_list); - ssl->alpn_client_proto_list = OPENSSL_malloc(protos_len); + ssl->alpn_client_proto_list = BUF_memdup(protos, protos_len); if (!ssl->alpn_client_proto_list) return 1; - memcpy(ssl->alpn_client_proto_list, protos, protos_len); ssl->alpn_client_proto_list_len = protos_len; return 0;
diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c index 6116f45..192a083 100644 --- a/ssl/t1_lib.c +++ b/ssl/t1_lib.c
@@ -1238,13 +1238,12 @@ else if (s->session && s->tlsext_session_ticket && s->tlsext_session_ticket->data) { - ticklen = s->tlsext_session_ticket->length; - s->session->tlsext_tick = OPENSSL_malloc(ticklen); + s->session->tlsext_tick = BUF_memdup( + s->tlsext_session_ticket->data, + s->tlsext_session_ticket->length); if (!s->session->tlsext_tick) return NULL; - memcpy(s->session->tlsext_tick, - s->tlsext_session_ticket->data, - ticklen); + ticklen = s->tlsext_session_ticket->length; s->session->tlsext_ticklen = ticklen; } else @@ -1687,13 +1686,12 @@ if (r == SSL_TLSEXT_ERR_OK) { if (s->s3->alpn_selected) OPENSSL_free(s->s3->alpn_selected); - s->s3->alpn_selected = OPENSSL_malloc(selected_len); + s->s3->alpn_selected = BUF_memdup(selected, selected_len); if (!s->s3->alpn_selected) { *out_alert = SSL_AD_INTERNAL_ERROR; return 0; } - memcpy(s->s3->alpn_selected, selected, selected_len); s->s3->alpn_selected_len = selected_len; } return 1;