From: Tomas Mraz Date: Wed, 9 Jun 2021 11:48:21 +0000 (+0200) Subject: BIO_write_ex: No error only on 0 bytes to write X-Git-Tag: openssl-3.0.0-beta1~96 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20778ea7dad8c4f659dbb5dfcb4fac896e51ed6a;p=thirdparty%2Fopenssl.git BIO_write_ex: No error only on 0 bytes to write Fixes #15682 Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/15672) --- diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index cdce1227960..af7ad05bcab 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -393,7 +393,13 @@ 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; + if (dlen == 0) { + /* no error */ + if (written != NULL) + *written = 0; + return 1; + } + 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 08104b1b92d..a2d8ab3af0e 100644 --- a/doc/man3/BIO_read.pod +++ b/doc/man3/BIO_read.pod @@ -27,7 +27,7 @@ stored in I<*readbytes>. BIO_write_ex() attempts to write I bytes from I to BIO I. If successful then the number of bytes written is stored in I<*written> -unless I is NULL. No data is written if I is NULL. +unless I is NULL. BIO_read() attempts to read I bytes from BIO I and places the data in I. @@ -59,7 +59,7 @@ BIO_puts() attempts to write a NUL-terminated string I to BIO I. BIO_read_ex() returns 1 if data was successfully read, and 0 otherwise. BIO_write_ex() returns 1 if no error was encountered writing data, 0 otherwise. -Write to NULL B is not considered as an error. +Requesting to write 0 bytes is not considered an error. BIO_write() returns -2 if the "write" operation is not implemented by the BIO or -1 on other errors. @@ -114,6 +114,9 @@ keep the '\n' at the end of the line in the buffer. BIO_get_line() was added in OpenSSL 3.0. +BIO_write_ex() returns 1 if the size of the data to write is 0 and the +I parameter of the function can be NULL since OpenSSL 3.0. + =head1 COPYRIGHT Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.