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>
Tue, 4 Feb 2020 14:39:29 +0000 (14:39 +0000)
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/10907)

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

index 3d2937594e71647cb4a7819de87e0a774d004b34..a3b3f21caba830bfb09d7b8dcabb16cd96d8d359 100644 (file)
@@ -526,7 +526,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 3abf2354a5e83c03885bad7e257b34c41c7e96c9..6c554ff6e6c54dbbf489d5610650a15fa758430a 100644 (file)
@@ -313,6 +313,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;
@@ -492,6 +494,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 9db3317e9a4071e34cb6aeaab061f296d97289ad..599790d654e3f3ee670af875dae96ed453be2790 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;