]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
pgcrypto: avoid recursive ResourceOwnerForget().
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 22 Jun 2026 16:59:16 +0000 (12:59 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 22 Jun 2026 16:59:16 +0000 (12:59 -0400)
Raising an error within a function using an OSSLCipher object led
to a complaint from ResourceOwnerForget and then a double-free crash,
because ResOwnerReleaseOSSLCipher forgot to unhook the OSSLCipher
object from its owner.  (The sibling logic for OSSLDigest objects got
this right, as did every other ReleaseResource function AFAICS.)

Oversight in cd694f60d.

Bug: #19527
Reported-by: Yuelin Wang <3020001251@tju.edu.cn>
Author: Yuelin Wang <3020001251@tju.edu.cn>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19527-6e7686960c6dce78@postgresql.org
Backpatch-through: 17

contrib/pgcrypto/openssl.c

index 8259de5e393d97195b39ff73c30a406560882d1b..b1692f07913a7195f5e9992a8bb991f36e7c178e 100644 (file)
@@ -800,5 +800,8 @@ px_find_cipher(const char *name, PX_Cipher **res)
 static void
 ResOwnerReleaseOSSLCipher(Datum res)
 {
-       free_openssl_cipher((OSSLCipher *) DatumGetPointer(res));
+       OSSLCipher *cipher = (OSSLCipher *) DatumGetPointer(res);
+
+       cipher->owner = NULL;
+       free_openssl_cipher(cipher);
 }