Teach more BIOs how to handle BIO_CTRL_EOF
authorMatt Caswell <matt@openssl.org>
Fri, 24 Jan 2020 16:07:51 +0000 (16:07 +0000)
committerMatt Caswell <matt@openssl.org>
Thu, 20 Feb 2020 17:02:31 +0000 (17:02 +0000)
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/10882)

crypto/bio/bss_acpt.c
crypto/bio/bss_conn.c
crypto/bio/bss_fd.c

index c6a2c388914bb2ef387fb8692a800af013dd054a..c9acf62dea6cc1912a62de1dbea8af68b0bca0cb 100644 (file)
@@ -527,7 +527,12 @@ static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
         break;
     case BIO_CTRL_DUP:
         break;
-
+    case BIO_CTRL_EOF:
+        if (b->next_bio == NULL)
+            ret = 0;
+        else
+            ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+        break;
     default:
         ret = 0;
         break;
index ad299ac716ef2ee321801ab70ac1be29ffaf551c..bb5049fb5939dc0a3d0a79bb8e4efbdb1aa09935 100644 (file)
@@ -316,6 +316,8 @@ static int conn_read(BIO *b, char *out, int outl)
         if (ret <= 0) {
             if (BIO_sock_should_retry(ret))
                 BIO_set_retry_read(b);
+            else if (ret == 0)
+                b->flags |= BIO_FLAGS_IN_EOF;
         }
     }
     return ret;
@@ -495,6 +497,9 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
             *fptr = data->info_callback;
         }
         break;
+    case BIO_CTRL_EOF:
+        ret = (b->flags & BIO_FLAGS_IN_EOF) != 0 ? 1 : 0;
+        break;
     default:
         ret = 0;
         break;
index 894b3ff9e7230cae3d0207fb4c270cb3fac00367..76ca0bd887f7cf0d792f2040f5a39be19e77bb7d 100644 (file)
@@ -123,6 +123,8 @@ static int fd_read(BIO *b, char *out, int outl)
         if (ret <= 0) {
             if (BIO_fd_should_retry(ret))
                 BIO_set_retry_read(b);
+            else if (ret == 0)
+                b->flags |= BIO_FLAGS_IN_EOF;
         }
     }
     return ret;
@@ -186,6 +188,9 @@ static long fd_ctrl(BIO *b, int cmd, long num, void *ptr)
     case BIO_CTRL_FLUSH:
         ret = 1;
         break;
+    case BIO_CTRL_EOF:
+        ret = (b->flags & BIO_FLAGS_IN_EOF) != 0 ? 1 : 0;
+        break;
     default:
         ret = 0;
         break;