From: Michael Paquier <michael@paquier.xyz>
To: Postgres hackers <pgsql-hackers@lists.postgresql.org>
Subject: Possible memory leak in pgcrypto with EVP_MD_CTX
Date: Thu, 15 Oct 2020 16:22:12 +0900
Message-ID: <20201015072212.GC2305@paquier.xyz> (raw)
Hi all,
It happens that pgcrypto has the following leak if a digest cannot be
initialized:
inline patch 1: contrib/pgcrypto/openssl.c (+1/-0 lines) download inline-1.patch--- a/contrib/pgcrypto/openssl.c+++ b/contrib/pgcrypto/openssl.c@@ -202,6 +202,7 @@ px_find_digest(const char *name, PX_MD **res)
}
if (EVP_DigestInit_ex(ctx, md, NULL) == 0)
{
+ EVP_MD_CTX_destroy(ctx);
pfree(digest);
return -1;
}
That's a bit annoying, because this memory is allocated directly by
OpenSSL, and Postgres does not know how to free it until it gets
registered in the list of open_digests that would be used by the
cleanup callback, so I think that we had better back-patch this fix.
Thoughts?
--
Michael
Patches and attachments:download all (3 files, .tar.gz)pgcrypto-leak.patch (text/x-diff, 353B) downloaddiff --git a/contrib/pgcrypto/openssl.c b/contrib/pgcrypto/openssl.cindex 90951a8ae7..ed96e4ce53 100644--- a/contrib/pgcrypto/openssl.c+++ b/contrib/pgcrypto/openssl.c@@ -202,6 +202,7 @@ px_find_digest(const char *name, PX_MD **res)
}
if (EVP_DigestInit_ex(ctx, md, NULL) == 0)
{
+ EVP_MD_CTX_destroy(ctx);
pfree(digest);
return -1;
}
signature.asc (application/pgp-signature, 832B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: michael@paquier.xyz, pgsql-hackers@lists.postgresql.org
Subject: Re: Possible memory leak in pgcrypto with EVP_MD_CTX
In-Reply-To: <20201015072212.GC2305@paquier.xyz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox