Make it build/run.
[openssl.git] / ssl / s3_pkt.c
index 41193bb7d162a42cd46dd6deca97de55ab175e57..5efc03e5ec64ca886131bd45d73f5fa544a85d92 100644 (file)
@@ -658,6 +658,21 @@ int ssl3_write_bytes(SSL *s, int type, const void *buf_, int len)
                        }
                }
 
+       /* ensure that if we end up with a smaller value of data to write 
+        * out than the the original len from a write which didn't complete 
+        * for non-blocking I/O and also somehow ended up avoiding 
+        * the check for this in ssl3_write_pending/SSL_R_BAD_WRITE_RETRY as
+        * it must never be possible to end up with (len-tot) as a large
+        * number that will then promptly send beyond the end of the users
+        * buffer ... so we trap and report the error in a way the user
+        * will notice
+        */
+       if ( len < tot)
+               {
+               SSLerr(SSL_F_SSL3_WRITE_BYTES,SSL_R_BAD_LENGTH);
+               return(-1);
+               }
+
        /* first check if there is a SSL3_BUFFER still being written
         * out.  This will happen with non blocking IO */
        if (wb->left != 0)
@@ -816,20 +831,6 @@ int ssl3_write_bytes(SSL *s, int type, const void *buf_, int len)
                return tot;
                }
 
-       /* ensure that if we end up with a smaller value of data to write 
-        * out than the the original len from a write which didn't complete 
-        * for non-blocking I/O and also somehow ended up avoiding 
-        * the check for this in ssl3_write_pending/SSL_R_BAD_WRITE_RETRY as
-        * it must never be possible to end up with (len-tot) as a large
-        * number that will then promptly send beyond the end of the users
-        * buffer ... so we trap and report the error in a way the user
-        * will notice
-        */
-       if ( len < tot)
-               {
-               SSLerr(SSL_F_SSL3_WRITE_BYTES,SSL_R_BAD_LENGTH);
-               return(-1);
-               }
 
        n=(len-tot);
        for (;;)
@@ -879,9 +880,6 @@ static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
        SSL3_BUFFER *wb=&(s->s3->wbuf);
        SSL_SESSION *sess;
 
-       if (wb->buf == NULL)
-               if (!ssl3_setup_write_buffer(s))
-                       return -1;
 
        /* first check if there is a SSL3_BUFFER still being written
         * out.  This will happen with non blocking IO */
@@ -897,6 +895,10 @@ static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
                /* if it went, fall through and send more stuff */
                }
 
+       if (wb->buf == NULL)
+               if (!ssl3_setup_write_buffer(s))
+                       return -1;
+
        if (len == 0 && !create_empty_fragment)
                return 0;