Provide RECORD_LAYER_set_data function
authorMatt Caswell <matt@openssl.org>
Mon, 2 Feb 2015 13:43:38 +0000 (13:43 +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/record/ssl3_buffer.c
ssl/record/ssl3_buffer.h
ssl/s23_clnt.c
ssl/s23_srvr.c

index 96e245e..4d91476 100644 (file)
@@ -170,6 +170,7 @@ void RECORD_LAYER_clear(RECORD_LAYER *rl);
 void RECORD_LAYER_release(RECORD_LAYER *rl);
 int RECORD_LAYER_read_pending(RECORD_LAYER *rl);
 int RECORD_LAYER_write_pending(RECORD_LAYER *rl);
+int RECORD_LAYER_set_data(RECORD_LAYER *rl, const unsigned char *buf, int len);
 __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 21ded63..376697f 100644 (file)
@@ -178,6 +178,22 @@ int RECORD_LAYER_write_pending(RECORD_LAYER *rl)
     return SSL3_BUFFER_get_left(&rl->wbuf) != 0;
 }
 
+int RECORD_LAYER_set_data(RECORD_LAYER *rl, const unsigned char *buf, int len)
+{
+    rl->s->packet_length = len;
+    if(len != 0) {
+        rl->s->rstate = SSL_ST_READ_HEADER;
+        if (!SSL3_BUFFER_is_initialised(&rl->rbuf))
+            if (!ssl3_setup_read_buffer(rl->s))
+                return 0;
+    }
+
+    rl->s->packet = SSL3_BUFFER_get_buf(&rl->rbuf);
+    SSL3_BUFFER_set_data(&rl->rbuf, buf, len);
+
+    return 1;
+}
+
 int ssl3_read_n(SSL *s, int n, int max, int extend)
 {
     /*
index 65dcd8a..2ea55c8 100644 (file)
 
 #include "../ssl_locl.h"
 
-void SSL3_BUFFER_set_data(SSL3_BUFFER *b, unsigned char *d, int n)
+void SSL3_BUFFER_set_data(SSL3_BUFFER *b, const unsigned char *d, int n)
 {
     if(d != NULL)
         memcpy(b->buf, d, n);
index 4668f45..8e55250 100644 (file)
@@ -127,7 +127,7 @@ typedef struct ssl3_buffer_st {
 #define SSL3_BUFFER_get_left(b)             ((b)->left)
 #define SSL3_BUFFER_is_initialised(b)       ((b)->buf != NULL)
 
-void SSL3_BUFFER_set_data(SSL3_BUFFER *b, unsigned char *d, int n);
+void SSL3_BUFFER_set_data(SSL3_BUFFER *b, const unsigned char *d, int n);
 void SSL3_BUFFER_release(SSL3_BUFFER *b);
 __owur int ssl3_setup_buffers(SSL *s);
 __owur int ssl3_setup_read_buffer(SSL *s);
index abefcaa..0bc5946 100644 (file)
@@ -573,13 +573,8 @@ static int ssl23_get_server_hello(SSL *s)
         /*
          * put the 7 bytes we have read into the input buffer for SSLv3
          */
-        s->rstate = SSL_ST_READ_HEADER;
-        s->packet_length = n;
-        if (!SSL3_BUFFER_is_initialised(RECORD_LAYER_get_rbuf(&s->rlayer)))
-            if (!ssl3_setup_read_buffer(s))
-                goto err;
-        s->packet = SSL3_BUFFER_get_buf(RECORD_LAYER_get_rbuf(&s->rlayer));
-        SSL3_BUFFER_set_data(RECORD_LAYER_get_rbuf(&s->rlayer), buf, n);
+        if(!RECORD_LAYER_set_data(&s->rlayer, buf, n))
+            goto err;
 
         s->handshake_func = s->method->ssl_connect;
     } else {
index 349d66b..3ff0ef6 100644 (file)
@@ -556,17 +556,11 @@ int ssl23_get_client_hello(SSL *s)
             /*
              * put the 'n' bytes we have read into the input buffer for SSLv3
              */
-            s->rstate = SSL_ST_READ_HEADER;
-            s->packet_length = n;
-            if (!SSL3_BUFFER_is_initialised(RECORD_LAYER_get_rbuf(&s->rlayer)))
-                if (!ssl3_setup_read_buffer(s))
-                    goto err;
-
-            s->packet = SSL3_BUFFER_get_buf(RECORD_LAYER_get_rbuf(&s->rlayer));
-            SSL3_BUFFER_set_data(RECORD_LAYER_get_rbuf(&s->rlayer), buf, n);
+            if(!RECORD_LAYER_set_data(&s->rlayer, buf, n))
+                goto err;
         } else {
-            s->packet_length = 0;
-            SSL3_BUFFER_set_data(RECORD_LAYER_get_rbuf(&s->rlayer), NULL, 0);
+            if(!RECORD_LAYER_set_data(&s->rlayer, NULL, 0))
+                goto err;
         }
         s->handshake_func = s->method->ssl_accept;
     } else {