BIO_s_mem() write: Skip early when input length is zero
authorRichard Levitte <levitte@openssl.org>
Fri, 4 May 2018 12:44:19 +0000 (14:44 +0200)
committerRichard Levitte <levitte@openssl.org>
Fri, 4 May 2018 22:14:30 +0000 (00:14 +0200)
When the input length is zero, just return zero early.  Otherwise,
there's a small chance that memory allocation is engaged, fails and
returns -1, which is a bit confusing when nothing should be written.

Fixes #4782 #4827

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
(Merged from https://github.com/openssl/openssl/pull/6175)

crypto/bio/bss_mem.c

index 7678a1df58c5273abb0f8c5aada95ca2090aea08..98819846dc902975588b2d52c7c8cd5d29cb2432 100644 (file)
@@ -216,6 +216,8 @@ static int mem_write(BIO *b, const char *in, int inl)
         goto end;
     }
     BIO_clear_retry_flags(b);
+    if (inl == 0)
+        return 0;
     blen = bbm->readp->length;
     mem_buf_sync(b);
     if (BUF_MEM_grow_clean(bbm->buf, blen + inl) == 0)