bio: add a malloc failed error to BIO_print
authorPauli <pauli@openssl.org>
Mon, 12 Apr 2021 01:36:50 +0000 (11:36 +1000)
committerPauli <pauli@openssl.org>
Wed, 14 Apr 2021 07:00:04 +0000 (17:00 +1000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14829)

crypto/bio/b_print.c

index 08d43d3bd5f711d4cffc3dcf42ecd9c4c01961e5..ba2c6c5b1fd12ef589d303455ea7a2f5893d1b4b 100644 (file)
@@ -835,9 +835,12 @@ doapr_outch(char **sbuffer,
             *sbuffer = NULL;
         } else {
             char *tmpbuf;
+
             tmpbuf = OPENSSL_realloc(*buffer, *maxlen);
-            if (tmpbuf == NULL)
+            if (tmpbuf == NULL) {
+                ERR_raise(ERR_LIB_BIO, ERR_R_MALLOC_FAILURE);
                 return 0;
+            }
             *buffer = tmpbuf;
         }
     }
@@ -929,6 +932,5 @@ int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
          * been large enough.)
          */
         return -1;
-    else
-        return (retlen <= INT_MAX) ? (int)retlen : -1;
+    return (retlen <= INT_MAX) ? (int)retlen : -1;
 }