Re: [PATCH] Add error message for out-of-memory in passwordFromFile()

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Joshua Shanks <jjshanks(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Add error message for out-of-memory in passwordFromFile()
Date: 2025-11-03 10:35:40
Message-ID: aQiFfFR1XFsbx8I8@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sun, Nov 02, 2025 at 09:09:55AM +0900, Michael Paquier wrote:
> Sounds OK to me. Nice catch. It's probably not worth bothering in
> the stable branches as the error is unlikely going to show up.

And, while checking the surroundings, I have noticed that your patch
is incomplete: passwordFromFile() is not designed currently in such a
way in fe-connect.c so as it is possible for its callers to make a
difference between one of the valid cases (like a dbname or user name
equal to NULL, service file that cannot be opened, etc.) and an error.

The point would be to have pqConnectOptions2() take its oom_error path
in the case you are pointing at. It seems to me that the correct
answer would be to extend passwordFromFile() with an extra "const char
**errmsg", where an error is saved, assign an error string in the
routine, check if the error pointer is set when exiting
passwordFromFile() in pqConnectOptions2(), and consume the error
properly before failing in pqConnectOptions2() with a CONNECTION_BAD.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bryan Green 2025-11-03 10:45:33 Re: Avoid overflow (src/backend/utils/adt/formatting.c)
Previous Message Ajin Cherian 2025-11-03 10:33:03 Re: Improve pg_sync_replication_slots() to wait for primary to advance