From bf3617413ce8781d84af3b67bfcb4f59b59a40e7 Mon Sep 17 00:00:00 2001
From: Fabian Keil <fk@fabiankeil.de>
Date: Tue, 5 Jan 2021 01:12:04 +0100
Subject: [PATCH] ssl_store_cert(): Check BIO_get_mem_data() return code

---
 openssl.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/openssl.c b/openssl.c
index ecfb6bf8..e3717af5 100644
--- a/openssl.c
+++ b/openssl.c
@@ -654,6 +654,13 @@ static int ssl_store_cert(struct client_state *csp, X509* crt)
    BIO_write(bio, &zero, 1);
 
    len = BIO_get_mem_data(bio, &bio_mem_data);
+   if (len <= 0)
+   {
+      log_error(LOG_LEVEL_ERROR, "BIO_get_mem_data() returned %d "
+         "while gathering certificate information", len);
+      ret = -1;
+      goto exit;
+   }
    encoded_text = html_encode(bio_mem_data);
    if (encoded_text == NULL)
    {
-- 
2.49.0