]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
err: fix coverity 1452768: dereference after null check
authorPauli <ppzgs1@gmail.com>
Mon, 22 Mar 2021 01:42:35 +0000 (11:42 +1000)
committerPauli <ppzgs1@gmail.com>
Tue, 23 Mar 2021 23:12:43 +0000 (09:12 +1000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14638)

crypto/err/err_blocks.c

index 0a2458f8014a218e623105c9351d0641f0f87336..0e3ca14f7277d6b129bf49ee9912e8c0e5152b69 100644 (file)
@@ -92,7 +92,8 @@ void ERR_vset_error(int lib, int reason, const char *fmt, va_list args)
         }
         if (printed_len < 0)
             printed_len = 0;
-        buf[printed_len] = '\0';
+        if (buf != NULL)
+            buf[printed_len] = '\0';
 
         /*
          * Try to reduce the size, but only if we maximized above.  If that
@@ -103,6 +104,7 @@ void ERR_vset_error(int lib, int reason, const char *fmt, va_list args)
         if ((rbuf = OPENSSL_realloc(buf, printed_len + 1)) != NULL) {
             buf = rbuf;
             buf_size = printed_len + 1;
+            buf[printed_len] = '\0';
         }
 
         if (buf != NULL)