From 810daf3759b6a77fcf5157b54a830c486d19916c Mon Sep 17 00:00:00 2001 From: jsing Date: Wed, 30 Nov 2022 01:56:18 +0000 Subject: [PATCH] Mostly align BIO_read()/BIO_write() return values with OpenSSL 3.x. For various historical reasons, there are a number of cases where our BIO_read() and BIO_write() return slightly different values to what OpenSSL 3.x does (of course OpenSSL 1.0 differs from OpenSSL 1.1 which differs from OpenSSL 3.x). Mostly align these - some further work will be needed. Issue raised by tb@ who also wrote some test code. --- lib/libcrypto/bio/bio_lib.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/libcrypto/bio/bio_lib.c b/lib/libcrypto/bio/bio_lib.c index 92c0d5eb1c3..b33ebe167bf 100644 --- a/lib/libcrypto/bio/bio_lib.c +++ b/lib/libcrypto/bio/bio_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bio_lib.c,v 1.37 2022/11/28 07:50:00 tb Exp $ */ +/* $OpenBSD: bio_lib.c,v 1.38 2022/11/30 01:56:18 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -322,12 +322,19 @@ BIO_read(BIO *b, void *out, int outl) size_t readbytes = 0; int ret; - if (b == NULL) - return (0); + if (b == NULL) { + BIOerror(ERR_R_PASSED_NULL_PARAMETER); + return (-1); + } - if (out == NULL || outl <= 0) + if (outl <= 0) return (0); + if (out == NULL) { + BIOerror(ERR_R_PASSED_NULL_PARAMETER); + return (-1); + } + if (b->method == NULL || b->method->bread == NULL) { BIOerror(BIO_R_UNSUPPORTED_METHOD); return (-2); @@ -372,12 +379,19 @@ BIO_write(BIO *b, const void *in, int inl) size_t writebytes = 0; int ret; - if (b == NULL) - return (0); + if (b == NULL) { + BIOerror(ERR_R_PASSED_NULL_PARAMETER); + return (-1); + } - if (in == NULL || inl <= 0) + if (inl <= 0) return (0); + if (in == NULL) { + BIOerror(ERR_R_PASSED_NULL_PARAMETER); + return (-1); + } + if (b->method == NULL || b->method->bwrite == NULL) { BIOerror(BIO_R_UNSUPPORTED_METHOD); return (-2); -- 2.20.1