Only auto-retry for DTLS if configured to do so
authorMatt Caswell <matt@openssl.org>
Thu, 3 May 2018 15:00:05 +0000 (16:00 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 11 May 2018 12:54:56 +0000 (13:54 +0100)
Otherwise we may end up in a hang when using blocking sockets

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

ssl/record/rec_layer_d1.c

index c753a54a2233a0e1f52cf872f1cfb864df8649ab..083dac4339fa6b45308a8b7dae68d6d6f796e70c 100644 (file)
@@ -849,6 +849,18 @@ int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
 
             dtls1_retransmit_buffered_messages(s);
             SSL3_RECORD_set_length(rr, 0);
+            if (!(s->mode & SSL_MODE_AUTO_RETRY)) {
+                if (SSL3_BUFFER_get_left(&s->rlayer.rbuf) == 0) {
+                    /* no read-ahead left? */
+                    BIO *bio;
+
+                    s->rwstate = SSL_READING;
+                    bio = SSL_get_rbio(s);
+                    BIO_clear_retry_flags(bio);
+                    BIO_set_retry_read(bio);
+                    return -1;
+                }
+            }
             goto start;
         }