From 33d23b87a0d06bc497a13b1998737a1ce469a785 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Fri, 30 Jan 2015 15:38:10 +0000 Subject: [PATCH] Move s->s3->rrec into s->rlayer Reviewed-by: Richard Levitte --- ssl/record/rec_layer.h | 6 +++++- ssl/s3_lib.c | 10 ++-------- ssl/ssl_lib.c | 20 ++++++++++++++++++++ ssl/ssl_locl.h | 3 +-- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ssl/record/rec_layer.h b/ssl/record/rec_layer.h index 4a75b216e0..574a252431 100644 --- a/ssl/record/rec_layer.h +++ b/ssl/record/rec_layer.h @@ -109,6 +109,8 @@ * */ +#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) diff --git a/ssl/s3_lib.c b/ssl/s3_lib.c index 101cf852a9..2097b79358 100644 --- a/ssl/s3_lib.c +++ b/ssl/s3_lib.c @@ -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; diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index bec54eb17a..cb3492a5e4 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -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); diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h index f845b67bfa..6925992c7b 100644 --- a/ssl/ssl_locl.h +++ b/ssl/ssl_locl.h @@ -165,8 +165,8 @@ # include # include -#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 */ -- 2.25.1