Move s->s3->rrec into s->rlayer
authorMatt Caswell <matt@openssl.org>
Fri, 30 Jan 2015 15:38:10 +0000 (15:38 +0000)
committerMatt Caswell <matt@openssl.org>
Thu, 26 Mar 2015 13:53:07 +0000 (13:53 +0000)
Reviewed-by: Richard Levitte <levitte@openssl.org>
ssl/record/rec_layer.h
ssl/s3_lib.c
ssl/ssl_lib.c
ssl/ssl_locl.h

index 4a75b216e074ce5fc0b7bc4f09c11d63884ec45e..574a2524317e168508aa272f60d748ab66ad2bbc 100644 (file)
  *
  */
 
+#include "../ssl_locl.h"
+
 typedef struct record_layer_st {
     /* The parent SSL structure */
     SSL *s;
@@ -117,9 +119,11 @@ typedef struct record_layer_st {
      * non-blocking reads)
      */
     int read_ahead;
+    /* read IO goes into here */
+    SSL3_BUFFER rbuf;
 } RECORD_LAYER;
 
 #define RECORD_LAYER_set_ssl(rl, s)             ((rl)->s = (s))
 #define RECORD_LAYER_set_read_ahead(rl, ra)     ((rl)->read_ahead = (ra))
 #define RECORD_LAYER_get_read_ahead(rl)         ((rl)->read_ahead)
-#define RECORD_LAYER_get_rbuf(rl)               (&(rl)->s->s3->rbuf)
+#define RECORD_LAYER_get_rbuf(rl)               (&(rl)->rbuf)
index 101cf852a9c97e7b6485d165c2caed9f56ea8291..2097b79358be312060ed4677f0ef3b63d5c42158 100644 (file)
@@ -3131,8 +3131,6 @@ void ssl3_free(SSL *s)
         return;
 
     ssl3_cleanup_key_block(s);
-    if (SSL3_BUFFER_is_initialised(RECORD_LAYER_get_rbuf(&s->rlayer)))
-        ssl3_release_read_buffer(s);
     if (s->s3->wbuf.buf != NULL)
         ssl3_release_write_buffer(s);
     if (s->s3->rrec.comp != NULL)
@@ -3164,8 +3162,8 @@ void ssl3_free(SSL *s)
 
 void ssl3_clear(SSL *s)
 {
-    unsigned char *rp, *wp;
-    size_t rlen, wlen;
+    unsigned char *wp;
+    size_t wlen;
     int init_extra;
 
     ssl3_cleanup_key_block(s);
@@ -3190,9 +3188,7 @@ void ssl3_clear(SSL *s)
 # endif                         /* !OPENSSL_NO_EC */
 #endif                          /* !OPENSSL_NO_TLSEXT */
 
-    rp = SSL3_BUFFER_get_buf(RECORD_LAYER_get_rbuf(&s->rlayer));
     wp = s->s3->wbuf.buf;
-    rlen = SSL3_BUFFER_get_len(RECORD_LAYER_get_rbuf(&s->rlayer));
     wlen = s->s3->wbuf.len;
     init_extra = s->s3->init_extra;
     BIO_free(s->s3->handshake_buffer);
@@ -3207,9 +3203,7 @@ void ssl3_clear(SSL *s)
     }
 #endif
     memset(s->s3, 0, sizeof *s->s3);
-    SSL3_BUFFER_set_buf(RECORD_LAYER_get_rbuf(&s->rlayer), rp);
     s->s3->wbuf.buf = wp;
-    SSL3_BUFFER_set_len(RECORD_LAYER_get_rbuf(&s->rlayer), rlen);
     s->s3->wbuf.len = wlen;
     s->s3->init_extra = init_extra;
 
index bec54eb17a904d113e1ee53b35c753cedde0aa4b..cb3492a5e433fd7d122c13b4e1cf88964561f792 100644 (file)
@@ -189,6 +189,9 @@ SSL3_ENC_METHOD ssl3_undef_enc_method = {
 
 int SSL_clear(SSL *s)
 {
+    unsigned char *rp;
+    size_t rlen;
+    int read_ahead;
 
     if (s->method == NULL) {
         SSLerr(SSL_F_SSL_CLEAR, SSL_R_NO_METHOD_SPECIFIED);
@@ -241,6 +244,20 @@ int SSL_clear(SSL *s)
             return (0);
     } 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));
+    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);
+
+    /* 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);
+
     return (1);
 }
 
@@ -599,6 +616,9 @@ void SSL_free(SSL *s)
     if (s->method != NULL)
         s->method->ssl_free(s);
 
+    if (SSL3_BUFFER_is_initialised(RECORD_LAYER_get_rbuf(&s->rlayer)))
+        ssl3_release_read_buffer(s);
+
     if (s->ctx)
         SSL_CTX_free(s->ctx);
 
index f845b67bfa848e9bcf5cfca5f59922d757948b37..6925992c7b1244f522a81dc975db4c472e16e3ca 100644 (file)
 # include <openssl/ssl.h>
 # include <openssl/symhacks.h>
 
-#include "record/rec_layer.h"
 #include "record/ssl3_buffer.h"
+#include "record/rec_layer.h"
 
 # ifdef OPENSSL_BUILD_SHLIBSSL
 #  undef OPENSSL_EXTERN
@@ -1281,7 +1281,6 @@ typedef struct ssl3_state_st {
     int empty_fragment_done;
     /* The value of 'extra' when the buffers were initialized */
     int init_extra;
-    SSL3_BUFFER rbuf;           /* read IO goes into here */
     SSL3_BUFFER wbuf;           /* write IO goes into here */
     SSL3_RECORD rrec;           /* each decoded record goes in here */
     SSL3_RECORD wrec;           /* goes out from here */