]> granicus.if.org Git - openssl/commitdiff
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 96e245e2c0520c59158d822a0e73b89005a76e0c..4d91476d4e74df7cab7a9ee4fe35c2cfebf4faac 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 21ded63e38bbe950a0a48434d8d2bcffca0d15d4..376697f744c150958763ec6c0dbd05cc379b284c 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 65dcd8a2923e08a5e1e4e974b256d4d9ebac1c2b..2ea55c8ba48dd77dbe3e1c9f40473bf0fabd96c0 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 4668f4507a83abcbab73935bde05880431b5fee2..8e55250a256e47847c9c2a7686c065a5538556e6 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 abefcaa0ef56fc0ec313918329cfbfc004131818..0bc59466660f1a3092f2e8ce31fa808d5dbd7f9e 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 349d66b47423868c6c6abfaa223371438578a8e4..3ff0ef642e4e5386d752d9561554ac5679d5d2eb 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 {