Ensure the WPACKET gets cleaned up in the event of an error
[openssl.git] / ssl / statem / statem_clnt.c
index cba0ece62fd4111650f513287ea3818f548c9a9f..4f123ddc981ebe8bc1f478c964b0ad8f8b73c568 100644 (file)
@@ -804,9 +804,8 @@ int tls_construct_client_hello(SSL *s)
     /* cookie stuff for DTLS */
     if (SSL_IS_DTLS(s)) {
         if (s->d1->cookie_len > sizeof(s->d1->cookie)
-                || !WPACKET_start_sub_packet_len(&pkt, 1)
-                || !WPACKET_memcpy(&pkt, s->d1->cookie, s->d1->cookie_len)
-                || !WPACKET_close(&pkt)) {
+                || !WPACKET_sub_memcpy(&pkt, s->d1->cookie, s->d1->cookie_len,
+                                       1)) {
             SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);
             goto err;
         }
@@ -876,6 +875,7 @@ int tls_construct_client_hello(SSL *s)
     return 1;
  err:
     ossl_statem_set_error(s);
+    WPACKET_cleanup(&pkt);
     return 0;
 }