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

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

On Mon, Nov 3, 2025 at 2:35 AM Michael Paquier <michael(at)paquier(dot)xyz> wrote:

> 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.
>

Thank you for the detailed feedback! This is my first C project
contribution, so I really appreciate you taking the time to explain the
proper error handling pattern.

I've updated the patch to address your concerns:

Changes in v2:
- Extended passwordFromFile() with const char **errmsg parameter to signal
actual errors
- Set *errmsg = "out of memory" for OOM cases (enlargePQExpBuffer and
strdup failures)
- Updated pqConnectOptions2() to check errmsg and fail with CONNECTION_BAD
when set
- Removed the PGconn *conn parameter since error reporting is now handled
by the caller
- Updated function comment to document the error signaling convention

Cheers,
Joshua

Attachment Content-Type Size
v2-0001-Improve-error-handling-in-passwordFromFile.patch application/octet-stream 4.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2025-11-04 05:30:51 Re: meson's in-tree libpq header search order vs -Dextra_include_dirs
Previous Message Philip Alger 2025-11-04 03:36:58 [PATCH] Add pretty formatting to pg_get_triggerdef