[openssl] master update

Dr. Paul Dale pauli at openssl.org
Tue Jun 8 05:17:29 UTC 2021


The branch master has been updated
       via  5d43bfa7d58c6af5e40d6615edc83c709df2852b (commit)
      from  f41fd10d90fb5202f4c05f8842b4a4f25afd51d0 (commit)


- Log -----------------------------------------------------------------
commit 5d43bfa7d58c6af5e40d6615edc83c709df2852b
Author: Dr. David von Oheimb <David.von.Oheimb at siemens.com>
Date:   Thu Jun 3 12:56:11 2021 +0200

    BIO_write-ex(): Improve behavior in corner cases and documentation
    
    Reviewed-by: Tomas Mraz <tomas at openssl.org>
    Reviewed-by: Paul Dale <pauli at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/15608)

-----------------------------------------------------------------------

Summary of changes:
 crypto/bio/bio_lib.c  | 17 +++++++++++------
 doc/man3/BIO_read.pod | 16 +++++++++++-----
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c
index 80b81db5c4..cdce122796 100644
--- a/crypto/bio/bio_lib.c
+++ b/crypto/bio/bio_lib.c
@@ -332,8 +332,11 @@ int BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *readbytes)
 static int bio_write_intern(BIO *b, const void *data, size_t dlen,
                             size_t *written)
 {
+    size_t local_written;
     int ret;
 
+    if (written != NULL)
+        *written = 0;
     /*
      * b == NULL is not an error but just means that zero bytes are written.
      * Do not raise an error here.
@@ -356,15 +359,17 @@ static int bio_write_intern(BIO *b, const void *data, size_t dlen,
         return -1;
     }
 
-    ret = b->method->bwrite(b, data, dlen, written);
+    ret = b->method->bwrite(b, data, dlen, &local_written);
 
     if (ret > 0)
-        b->num_write += (uint64_t)*written;
+        b->num_write += (uint64_t)local_written;
 
     if (HAS_CALLBACK(b))
         ret = (int)bio_call_callback(b, BIO_CB_WRITE | BIO_CB_RETURN, data,
-                                     dlen, 0, 0L, ret, written);
+                                     dlen, 0, 0L, ret, &local_written);
 
+    if (written != NULL)
+        *written = local_written;
     return ret;
 }
 
@@ -373,13 +378,13 @@ int BIO_write(BIO *b, const void *data, int dlen)
     size_t written;
     int ret;
 
-    if (dlen < 0)
+    if (dlen <= 0)
         return 0;
 
     ret = bio_write_intern(b, data, (size_t)dlen, &written);
 
     if (ret > 0) {
-        /* *written should always be <= dlen */
+        /* written should always be <= dlen */
         ret = (int)written;
     }
 
@@ -388,7 +393,7 @@ int BIO_write(BIO *b, const void *data, int dlen)
 
 int BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written)
 {
-    return bio_write_intern(b, data, dlen, written) > 0;
+    return bio_write_intern(b, data, dlen, written) >= 0;
 }
 
 int BIO_puts(BIO *b, const char *buf)
diff --git a/doc/man3/BIO_read.pod b/doc/man3/BIO_read.pod
index d9201ef3b7..08104b1b92 100644
--- a/doc/man3/BIO_read.pod
+++ b/doc/man3/BIO_read.pod
@@ -25,8 +25,9 @@ BIO_read_ex() attempts to read I<dlen> bytes from BIO I<b> and places the data
 in I<data>. If any bytes were successfully read then the number of bytes read is
 stored in I<*readbytes>.
 
-BIO_write_ex() attempts to write I<dlen> bytes from I<data> to BIO I<b>. If
-successful then the number of bytes written is stored in I<*written>.
+BIO_write_ex() attempts to write I<dlen> bytes from I<data> to BIO I<b>.
+If successful then the number of bytes written is stored in I<*written>
+unless I<written> is NULL. No data is written if I<b> is NULL.
 
 BIO_read() attempts to read I<len> bytes from BIO I<b> and places
 the data in I<buf>.
@@ -55,10 +56,15 @@ BIO_puts() attempts to write a NUL-terminated string I<buf> to BIO I<b>.
 
 =head1 RETURN VALUES
 
-BIO_read_ex() and BIO_write_ex() return 1 if data was successfully read or
-written, and 0 otherwise.
+BIO_read_ex() returns 1 if data was successfully read, and 0 otherwise.
 
-BIO_write() and BIO_write_ex() return 0 if the BIO I<b> is NULL.
+BIO_write_ex() returns 1 if no error was encountered writing data, 0 otherwise.
+Write to NULL B<BIO> is not considered as an error.
+
+BIO_write() returns -2 if the "write" operation is not implemented by the BIO
+or -1 on other errors.
+Otherwise it returns the number of bytes written.
+This may be 0 if the BIO I<b> is NULL or I<dlen <= 0>.
 
 BIO_gets() returns -2 if the "gets" operation is not implemented by the BIO
 or -1 on other errors.


More information about the openssl-commits mailing list