Re: NULL pointer dereference in syslogger with load_libraries() and -DEXEC_BACKEND at startup

From: "Euler Taveira" <euler(at)eulerto(dot)com>
To: "Michael Paquier" <michael(at)paquier(dot)xyz>, "Postgres hackers" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Subject: Re: NULL pointer dereference in syslogger with load_libraries() and -DEXEC_BACKEND at startup
Date: 2026-05-26 02:39:54
Message-ID: 746eb248-0787-4633-94fe-f3dbef249f85@app.fastmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, May 25, 2026, at 5:21 AM, Michael Paquier wrote:
> On Mon, May 25, 2026 at 04:45:41PM +0900, Michael Paquier wrote:
>> I did not take the cycles necessary for a bisect, but it looks like
>> this has been around for a few months at least. I have pinged
>> f3c9e341cdf1 as a safe startup point for now, so that's a 2026 issue.
>
> Well, well:
> 0c8e082fba8d36434552d3d7800abda54acafd57 is the first bad commit
> committer: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
> date: Wed, 4 Feb 2026 16:56:57 +0100
> Assign "backend" type earlier during process start-up
>
> I have also checked manually a revert of this commit, and saw that the
> problem is gone, so it does not look like I have messed up my bisect.
>

It seems I was too optimistic about this patch. Since the commit 0c8e082fba8
sets MyBackendType to B_LOGGER earlier, it breaks the following assumption in
syslogger.c.

/*
* If we're told to write to a structured log file, but it's not open,
* dump the data to syslogFile (which is always open) instead. This can
* happen if structured output is enabled after postmaster start and we've
* been unable to open logFile. There are also race conditions during a
* parameter change whereby backends might send us structured output
* before we open the logFile or after we close it. Writing formatted
* output to the regular log file isn't great, but it beats dropping log
* output on the floor.

It shouldn't assume syslogFile is always open. The send_message_to_server_log()
shouldn't be executing the following code path in this case.

/* If in the syslogger process, try to write messages direct to file */
if (MyBackendType == B_LOGGER)
write_syslogger_file(buf.data, buf.len, LOG_DESTINATION_STDERR);

It could set MyBackendType only if child_type != B_LOGGER during
launch_backend.c and set it at the same code path as in the past. However, I
consider this solution ugly and hackish.

--
Euler Taveira
EDB https://www.enterprisedb.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2026-05-26 03:20:04 Re: Row pattern recognition
Previous Message Amit Kapila 2026-05-26 02:03:48 Re: Bound memory usage during manual slot sync retries