Move init of the WPACKET into write_state_machine()
[openssl.git] / ssl / statem / statem.c
index f00480803c71883712cbe5dcc8e05f1c3907c33f..1ad421b07b942797a3a4f0f1b4cc4fd0b3978fd3 100644 (file)
@@ -708,8 +708,9 @@ static SUB_STATE_RETURN write_state_machine(SSL *s)
     WRITE_TRAN(*transition) (SSL *s);
     WORK_STATE(*pre_work) (SSL *s, WORK_STATE wst);
     WORK_STATE(*post_work) (SSL *s, WORK_STATE wst);
-    int (*construct_message) (SSL *s);
+    int (*construct_message) (SSL *s, WPACKET *pkt);
     void (*cb) (const SSL *ssl, int type, int val) = NULL;
+    WPACKET pkt;
 
     cb = get_callback(s);
 
@@ -764,8 +765,13 @@ static SUB_STATE_RETURN write_state_machine(SSL *s)
             case WORK_FINISHED_STOP:
                 return SUB_STATE_END_HANDSHAKE;
             }
-            if (construct_message(s) == 0)
+            if (!WPACKET_init(&pkt, s->init_buf)
+                    || !construct_message(s, &pkt)
+                    || !WPACKET_finish(&pkt)) {
+                WPACKET_cleanup(&pkt);
+                ossl_statem_set_error(s);
                 return SUB_STATE_ERROR;
+            }
 
             /* Fall through */