pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix allocation logic of cryptohash context data with OpenSSL
Date: Thu, 07 Jan 2021 01:27:49 +0000
Message-ID: <E1kxK5d-0004h5-GI@gemulon.postgresql.org> (raw)

Fix allocation logic of cryptohash context data with OpenSSL

The allocation of the cryptohash context data when building with OpenSSL
was happening in the memory context of the caller of
pg_cryptohash_create(), which could lead to issues with resowner cleanup
if cascading resources are cleaned up on an error.  Like other
facilities using resowners, move the base allocation to TopMemoryContext
to ensure a correct cleanup on failure.

The resulting code gets simpler with this commit as the context data is
now hold by a unique opaque pointer, so as there is only one single
allocation done in TopMemoryContext.

After discussion, also change the cryptohash subroutines to return an
error if the caller provides NULL for the context data to ease error
detection on OOM.

Author: Heikki Linnakangas
Discussion: https://postgr.es/m/X9xbuEoiU3dlImfa@paquier.xyz

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/55fe26a4b580b17d721c5accb842cc6a08295273

Modified Files
--------------
src/common/cryptohash.c          | 111 ++++++++++++++++-----------------------
src/common/cryptohash_openssl.c  |  86 ++++++++++++------------------
src/include/common/cryptohash.h  |   8 +--
src/tools/pgindent/typedefs.list |   1 -
4 files changed, 81 insertions(+), 125 deletions(-)



Message-ID: <E1kxK5d-0004h5-GI@gemulon.postgresql.org>
Permalink:  ../E1kxK5d-0004h5-GI@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kxK5d-0004h5-GI@gemulon.postgresql.org

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz
  Subject: Re: pgsql: Fix allocation logic of cryptohash context data with OpenSSL
  In-Reply-To: <E1kxK5d-0004h5-GI@gemulon.postgresql.org>
  References: <E1kxK5d-0004h5-GI@gemulon.postgresql.org>

* 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