pgsql: Avoid null pointer crash after pg_localtime()/pg_gmtime() failur

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid null pointer crash after pg_localtime()/pg_gmtime() failur
Date: 2026-11-25 02:20:14
Message-ID: E1xW2cI-00000000D0I-1oYk@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid null pointer crash after pg_localtime()/pg_gmtime() failure.

localtime(3) and gmtime(3) are specified to return NULL on failure,
and our versions do that too, but most of our call sites did not
guard against such a result. Make them more wary.

Many of these call sites pass the result straight to pg_strftime(),
so the path of least resistance is to harden that function rather
than touch all its callers. I made it return an empty string, as
it already does for other failure cases. In other places the
fallback behavior can be to use UTC timezone.

The possible causes of a NULL result seem to be (a) malloc() failure
or (b) integer overflow in time calculations. Anthropic found a
case where an integer overflow could be triggered with a contrived
POSIX timezone setting; that seems to be a bug in the 2026b tzcode
release we're using in master, which has already been repaired
upstream. Since it won't occur with sane timezone settings, I'm
not going to worry about fixing it before our next tzcode merge.
We should guard against these failure returns in any case.

Reported to security@ by Anthropic, but they described it as a
non-security bug, which matches our policy: a plain NULL-pointer
dereference without any worse consequences is not security material.

Reported-by: Anthropic OSS program
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Backpatch-through: 15

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/27da34042b82747387f6b0c2e0cf3dcea976ced6

Modified Files
--------------
src/backend/postmaster/syslogger.c | 7 +++--
src/backend/utils/adt/timestamp.c | 52 ++++++++++++++++++++------------------
src/timezone/strftime.c | 11 ++++++++
3 files changed, 43 insertions(+), 27 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2026-11-25 02:20:15 pgsql: Avoid null pointer crash after pg_localtime()/pg_gmtime() failur
Previous Message Manu 2026-11-25 01:42:32 Re: pgsql: Don't trust NOT NULL on virtual generated columns of partitioned