Fix SSL_pending() for DTLS
authorMatt Caswell <matt@openssl.org>
Thu, 19 Apr 2018 15:42:39 +0000 (16:42 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 20 Apr 2018 10:51:57 +0000 (11:51 +0100)
DTLS was not correctly returning the number of pending bytes left in
a call to SSL_pending(). This makes the detection of truncated packets
almost impossible.

Fixes #5478

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

ssl/record/rec_layer_d1.c

index ddb3a6183213b29431e613a504bfaeca5a56cde3..90029a25355085f4a5787db54bc767498d61da11 100644 (file)
@@ -418,6 +418,7 @@ int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
     /* get new packet if necessary */
     if ((SSL3_RECORD_get_length(rr) == 0)
         || (s->rlayer.rstate == SSL_ST_READ_BODY)) {
+        RECORD_LAYER_set_numrpipes(&s->rlayer, 0);
         iret = dtls1_get_record(s);
         if (iret <= 0) {
             iret = dtls1_read_failed(s, iret);
@@ -430,6 +431,7 @@ int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
             else
                 goto start;
         }
+        RECORD_LAYER_set_numrpipes(&s->rlayer, 1);
     }
 
     /*