Mark a zero length record as read
authorMatt Caswell <matt@openssl.org>
Mon, 6 Nov 2017 16:52:06 +0000 (16:52 +0000)
committerMatt Caswell <matt@openssl.org>
Tue, 7 Nov 2017 11:14:00 +0000 (11:14 +0000)
If SSL_read() is called with a zero length buffer, and we read a zero length
record then we should mark that record as read.

Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4686)

ssl/record/rec_layer_s3.c

index 5945d187482f8b40cbb2be8a4dbda900a83aa7aa..95026c6e573d21d9261d5406700da977728b3e3e 100644 (file)
@@ -1133,8 +1133,16 @@ int ssl3_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
         if (recvd_type != NULL)
             *recvd_type = SSL3_RECORD_get_type(rr);
 
-        if (len <= 0)
-            return (len);
+        if (len <= 0) {
+            /*
+             * Mark a zero length record as read. This ensures multiple calls to
+             * SSL_read() with a zero length buffer will eventually cause
+             * SSL_pending() to report data as being available.
+             */
+            if (SSL3_RECORD_get_length(rr) == 0)
+                SSL3_RECORD_set_read(rr);
+            return len;
+        }
 
         read_bytes = 0;
         do {