From: zsugabubus Date: Mon, 18 Jan 2021 14:33:57 +0000 (+0100) Subject: Check input size before NULL pointer test inside mem_write() X-Git-Tag: openssl-3.0.0-alpha11~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=daa86f9e6bfeb83a5db976c6351f7a568a8d6dcb;p=thirdparty%2Fopenssl.git Check input size before NULL pointer test inside mem_write() Checking is performed after the read-only test so it catches such errors earlier. CLA: trivial Reviewed-by: Dmitry Belyavskiy Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/13786) --- diff --git a/crypto/bio/bss_mem.c b/crypto/bio/bss_mem.c index 3bdf4579660..fe362d87fc7 100644 --- a/crypto/bio/bss_mem.c +++ b/crypto/bio/bss_mem.c @@ -221,10 +221,6 @@ static int mem_write(BIO *b, const char *in, int inl) int blen; BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr; - if (in == NULL) { - ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER); - goto end; - } if (b->flags & BIO_FLAGS_MEM_RDONLY) { ERR_raise(ERR_LIB_BIO, BIO_R_WRITE_TO_READ_ONLY_BIO); goto end; @@ -232,6 +228,10 @@ static int mem_write(BIO *b, const char *in, int inl) BIO_clear_retry_flags(b); if (inl == 0) return 0; + if (in == NULL) { + ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER); + goto end; + } blen = bbm->readp->length; mem_buf_sync(b); if (BUF_MEM_grow_clean(bbm->buf, blen + inl) == 0)