Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2021-01-07 Thread Michael Paquier
On Thu, Jan 07, 2021 at 09:51:00AM +0200, Heikki Linnakangas wrote: > Hmm. Perhaps it would be best to change all the errors in mock > authentication to COMMERROR. It'd be nice to have an accurate error message > in the log, but no need to send it to the client. Yeah, we could do that. Still,

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2021-01-06 Thread Heikki Linnakangas
On 07/01/2021 06:15, Michael Paquier wrote: On Wed, Jan 06, 2021 at 03:58:22PM +0200, Heikki Linnakangas wrote: contrib/pgcrypto/internal-sha2.c and src/backend/utils/adt/cryptohashfuncs.c: the call to pg_cryptohash_create() is missing check for NULL result. With your latest patch, that's OK

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2021-01-06 Thread Michael Paquier
On Wed, Jan 06, 2021 at 03:58:22PM +0200, Heikki Linnakangas wrote: > contrib/pgcrypto/internal-sha2.c and > src/backend/utils/adt/cryptohashfuncs.c: the call to pg_cryptohash_create() > is missing check for NULL result. With your latest patch, that's OK because > the subsequent

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2021-01-06 Thread Michael Paquier
On Wed, Jan 06, 2021 at 03:27:03PM +0200, Heikki Linnakangas wrote: > Looks fine to me. Thanks, I have been able to get this part done as of 55fe26a. -- Michael signature.asc Description: PGP signature

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2021-01-06 Thread Heikki Linnakangas
On 25/12/2020 02:57, Michael Paquier wrote: On Mon, Dec 21, 2020 at 04:28:26PM -0500, Robert Haas wrote: TBH, I think there's no point in return an error here at all, because it's totally non-specific. You have no idea what failed, just that something failed. Blech. If we want to check that ctx

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2021-01-06 Thread Heikki Linnakangas
On 06/01/2021 13:42, Michael Paquier wrote: On Sat, Dec 19, 2020 at 03:13:50PM +0900, Michael Paquier wrote: At the same time, I have taken care of your comment from upthread to return a failure if the caller passes NULL for the context, and adjusted some comments. What do you think of the

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2021-01-06 Thread Michael Paquier
On Sat, Dec 19, 2020 at 03:13:50PM +0900, Michael Paquier wrote: > At the same time, I have taken care of your comment from upthread to > return a failure if the caller passes NULL for the context, and > adjusted some comments. What do you think of the attached? I have looked again at this

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2020-12-24 Thread Michael Paquier
On Mon, Dec 21, 2020 at 04:28:26PM -0500, Robert Haas wrote: > TBH, I think there's no point in return an error here at all, because > it's totally non-specific. You have no idea what failed, just that > something failed. Blech. If we want to check that ctx is non-NULL, we > should do that with an

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2020-12-21 Thread Robert Haas
On Fri, Dec 18, 2020 at 6:04 AM Heikki Linnakangas wrote: > BTW, it's a bit weird that the pg_cryptohash_init/update/final() > functions return success, if the ctx argument is NULL. It would seem > more sensible for them to return an error. That way, if a caller forgets > to check for NULL result

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2020-12-18 Thread Michael Paquier
On Fri, Dec 18, 2020 at 11:51:55AM +0200, Heikki Linnakangas wrote: > On 18/12/2020 11:35, Heikki Linnakangas wrote: > > BTW, looking at pg_cryptohash_ctx and pg_cryptohash_state, why do we > > need two structs? They're both allocated and controlled by the > > cryptohash implementation. It would

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2020-12-18 Thread Michael Paquier
On Fri, Dec 18, 2020 at 01:04:27PM +0200, Heikki Linnakangas wrote: > BTW, it's a bit weird that the pg_cryptohash_init/update/final() functions > return success, if the ctx argument is NULL. It would seem more sensible for > them to return an error. Okay. > That way, if a caller forgets to

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2020-12-18 Thread Heikki Linnakangas
On 18/12/2020 12:55, Heikki Linnakangas wrote: On 18/12/2020 12:10, Michael Paquier wrote: On Fri, Dec 18, 2020 at 11:35:14AM +0200, Heikki Linnakangas wrote: pg_cryptohash_create() is now susceptible to leaking memory in TopMemoryContext, if the allocations fail. I think the attached should

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2020-12-18 Thread Heikki Linnakangas
On 18/12/2020 12:10, Michael Paquier wrote: On Fri, Dec 18, 2020 at 11:35:14AM +0200, Heikki Linnakangas wrote: pg_cryptohash_create() is now susceptible to leaking memory in TopMemoryContext, if the allocations fail. I think the attached should fix it (but I haven't tested it at all). Yeah,

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2020-12-18 Thread Michael Paquier
On Fri, Dec 18, 2020 at 11:51:55AM +0200, Heikki Linnakangas wrote: > Something like this. Passes regression tests, but otherwise untested. ... And I wanted to keep track of the type of cryptohash directly in the shared structure. ;) -- Michael signature.asc Description: PGP signature

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2020-12-18 Thread Michael Paquier
On Fri, Dec 18, 2020 at 11:35:14AM +0200, Heikki Linnakangas wrote: > pg_cryptohash_create() is now susceptible to leaking memory in > TopMemoryContext, if the allocations fail. I think the attached should fix > it (but I haven't tested it at all). Yeah, you are right here. If the second

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2020-12-18 Thread Heikki Linnakangas
On 18/12/2020 11:35, Heikki Linnakangas wrote: BTW, looking at pg_cryptohash_ctx and pg_cryptohash_state, why do we need two structs? They're both allocated and controlled by the cryptohash implementation. It would seem simpler to have just one. Something like this. Passes regression tests,

Re: Incorrect allocation handling for cryptohash functions with OpenSSL

2020-12-18 Thread Heikki Linnakangas
On 18/12/2020 09:35, Michael Paquier wrote: Hi all, As of the work done in 87ae9691, I have played with error injections in the code paths using this code, but forgot to count for cases where cascading resowner cleanups are involved. Like other resources (JIT, DSM, etc.), this requires an

Incorrect allocation handling for cryptohash functions with OpenSSL

2020-12-17 Thread Michael Paquier
Hi all, As of the work done in 87ae9691, I have played with error injections in the code paths using this code, but forgot to count for cases where cascading resowner cleanups are involved. Like other resources (JIT, DSM, etc.), this requires an allocation in TopMemoryContext to make sure that