From a60b533125c9316a8433b67ad8858d936fe2a426 Mon Sep 17 00:00:00 2001 From: Pauli Date: Mon, 22 Mar 2021 11:42:35 +1000 Subject: [PATCH] err: fix coverity 1452768: dereference after null check Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/14638) --- crypto/err/err_blocks.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crypto/err/err_blocks.c b/crypto/err/err_blocks.c index 0a2458f8014..0e3ca14f727 100644 --- a/crypto/err/err_blocks.c +++ b/crypto/err/err_blocks.c @@ -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) -- 2.47.2