Create RECORD_LAYER_clear function.
authorMatt Caswell <matt@openssl.org>
Mon, 2 Feb 2015 11:53:20 +0000 (11:53 +0000)
committerMatt Caswell <matt@openssl.org>
Thu, 26 Mar 2015 15:01:59 +0000 (15:01 +0000)
Reviewed-by: Richard Levitte <levitte@openssl.org>
ssl/record/rec_layer.h
ssl/record/s3_pkt.c
ssl/ssl_lib.c

index 1f6fea1..648fd3c 100644 (file)
@@ -166,6 +166,7 @@ typedef struct record_layer_st {
 #define RECORD_LAYER_get_rrec(rl)               (&(rl)->rrec)
 #define RECORD_LAYER_get_wrec(rl)               (&(rl)->wrec)
 
+void RECORD_LAYER_clear(RECORD_LAYER *rl);
 __owur int ssl23_read_bytes(SSL *s, int n);
 __owur int ssl23_write_bytes(SSL *s);
 __owur int ssl3_write_bytes(SSL *s, int type, const void *buf, int len);
index b9d0575..ec3f0a1 100644 (file)
 # define EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK 0
 #endif
 
+void RECORD_LAYER_clear(RECORD_LAYER *rl)
+{
+    unsigned char *rp, *wp;
+    size_t rlen, wlen;
+    int read_ahead;
+    SSL *s;
+
+    s = rl->s;
+    read_ahead = rl->read_ahead;
+    rp = SSL3_BUFFER_get_buf(&rl->rbuf);
+    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));
+    SSL3_BUFFER_set_buf(&rl->rbuf, rp);
+    SSL3_BUFFER_set_len(&rl->rbuf, rlen);
+    SSL3_BUFFER_set_buf(&rl->wbuf, wp);
+    SSL3_BUFFER_set_len(&rl->wbuf, wlen);
+
+    /* Do I need to do this? As far as I can tell read_ahead did not
+     * previously get reset by SSL_clear...so I'll keep it that way..but is
+     * that right?
+     */
+    rl->read_ahead = read_ahead;
+    rl->s = s;
+}
+
 int ssl3_read_n(SSL *s, int n, int max, int extend)
 {
     /*
index 727f913..0298501 100644 (file)
@@ -189,10 +189,6 @@ SSL3_ENC_METHOD ssl3_undef_enc_method = {
 
 int SSL_clear(SSL *s)
 {
-    unsigned char *rp, *wp;
-    size_t rlen, wlen;
-    int read_ahead;
-
     if (s->method == NULL) {
         SSLerr(SSL_F_SSL_CLEAR, SSL_R_NO_METHOD_SPECIFIED);
         return (0);
@@ -245,23 +241,7 @@ int SSL_clear(SSL *s)
     } else
         s->method->ssl_clear(s);
 
-    read_ahead = RECORD_LAYER_get_read_ahead(&s->rlayer);
-    rp = SSL3_BUFFER_get_buf(RECORD_LAYER_get_rbuf(&s->rlayer));
-    rlen = SSL3_BUFFER_get_len(RECORD_LAYER_get_rbuf(&s->rlayer));
-    wp = SSL3_BUFFER_get_buf(RECORD_LAYER_get_wbuf(&s->rlayer));
-    wlen = SSL3_BUFFER_get_len(RECORD_LAYER_get_wbuf(&s->rlayer));
-    memset(&s->rlayer, 0, sizeof s->rlayer);
-    SSL3_BUFFER_set_buf(RECORD_LAYER_get_rbuf(&s->rlayer), rp);
-    SSL3_BUFFER_set_len(RECORD_LAYER_get_rbuf(&s->rlayer), rlen);
-    SSL3_BUFFER_set_buf(RECORD_LAYER_get_wbuf(&s->rlayer), wp);
-    SSL3_BUFFER_set_len(RECORD_LAYER_get_wbuf(&s->rlayer), wlen);
-
-    /* Do I need to do this? As far as I can tell read_ahead did not
-     * previously get reset by SSL_clear...so I'll keep it that way..but is
-     * that right?
-     */
-    RECORD_LAYER_set_read_ahead(&s->rlayer, read_ahead);
-    RECORD_LAYER_set_ssl(&s->rlayer, s);
+    RECORD_LAYER_clear(&s->rlayer);
 
     return (1);
 }