From 5f7832909b9500e8d97291c3095ae095f58be5e5 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Wed, 20 May 2020 16:53:05 +0200 Subject: [PATCH] BIO_new_mem_buf with negative len should take strlen of buf as len --- src/ssl.c | 5 ++++- tests/api.c | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index 255ec7cc8..95e228442 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -14913,7 +14913,7 @@ int wolfSSL_set_compression(WOLFSSL* ssl) { WOLFSSL_BIO* bio = NULL; - if (buf == NULL || len < 0) { + if (buf == NULL) { return bio; } @@ -14922,6 +14922,9 @@ int wolfSSL_set_compression(WOLFSSL* ssl) return bio; } + if (len < 0) { + len = XSTRLEN(buf); + } bio->num = bio->wrSz = len; bio->ptr = (byte*)XMALLOC(len, 0, DYNAMIC_TYPE_OPENSSL); if (bio->ptr == NULL) { diff --git a/tests/api.c b/tests/api.c index c230c3c4a..507d59116 100644 --- a/tests/api.c +++ b/tests/api.c @@ -24983,10 +24983,9 @@ static void test_wolfSSL_BIO_gets(void) /* try with bad args */ AssertNull(bio = BIO_new_mem_buf(NULL, sizeof(msg))); - AssertNull(bio = BIO_new_mem_buf((void*)msg, -1)); /* try with real msg */ - AssertNotNull(bio = BIO_new_mem_buf((void*)msg, sizeof(msg))); + AssertNotNull(bio = BIO_new_mem_buf((void*)msg, -1)); XMEMSET(bio_buffer, 0, bufferSz); AssertNotNull(BIO_push(bio, BIO_new(BIO_s_bio()))); AssertNull(bio2 = BIO_find_type(bio, BIO_TYPE_FILE));