diff options
author | Matt Caswell <matt@openssl.org> | 2016-09-20 12:26:46 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-09-20 14:17:50 +0100 |
commit | 85a7a5e6ef633d2b01ef9792463a36b507a35a6a (patch) | |
tree | fcaa153f3d0eb96da6fcba09477046b4630e498e /ssl/statem/statem_dtls.c | |
parent | 4f89bfbf1538eb5ad502f646f78f4e40092bfcfe (diff) | |
download | openssl-new-85a7a5e6ef633d2b01ef9792463a36b507a35a6a.tar.gz |
Convert CCS construction to WPACKET
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'ssl/statem/statem_dtls.c')
-rw-r--r-- | ssl/statem/statem_dtls.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/ssl/statem/statem_dtls.c b/ssl/statem/statem_dtls.c index b9a53b0543..3146f77b0d 100644 --- a/ssl/statem/statem_dtls.c +++ b/ssl/statem/statem_dtls.c @@ -873,19 +873,33 @@ static int dtls_get_reassembled_message(SSL *s, long *len) */ int dtls_construct_change_cipher_spec(SSL *s) { - unsigned char *p; + WPACKET pkt; + + if (!WPACKET_init(&pkt, s->init_buf) + || !WPACKET_put_bytes(&pkt, SSL3_MT_CCS, 1)) { + SSLerr(SSL_F_TLS_CONSTRUCT_FINISHED, ERR_R_INTERNAL_ERROR); + goto err; + } - p = (unsigned char *)s->init_buf->data; - *p++ = SSL3_MT_CCS; s->d1->handshake_write_seq = s->d1->next_handshake_write_seq; s->init_num = DTLS1_CCS_HEADER_LENGTH; if (s->version == DTLS1_BAD_VER) { s->d1->next_handshake_write_seq++; - s2n(s->d1->handshake_write_seq, p); + + if (!WPACKET_put_bytes(&pkt, s->d1->handshake_write_seq, 2)) { + SSLerr(SSL_F_TLS_CONSTRUCT_FINISHED, ERR_R_INTERNAL_ERROR); + goto err; + } + s->init_num += 2; } + if (!WPACKET_finish(&pkt)) { + SSLerr(SSL_F_TLS_CONSTRUCT_FINISHED, ERR_R_INTERNAL_ERROR); + goto err; + } + s->init_off = 0; dtls1_set_message_header_int(s, SSL3_MT_CCS, 0, @@ -894,10 +908,16 @@ int dtls_construct_change_cipher_spec(SSL *s) /* buffer the message to handle re-xmits */ if (!dtls1_buffer_message(s, 1)) { SSLerr(SSL_F_DTLS_CONSTRUCT_CHANGE_CIPHER_SPEC, ERR_R_INTERNAL_ERROR); - return 0; + goto err ; } return 1; + err: + WPACKET_cleanup(&pkt); + ossl_statem_set_error(s); + ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); + + return 0; } #ifndef OPENSSL_NO_SCTP |