pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid null pointer crash after pg_localtime()/pg_gmtime() failur
Date: Wed, 25 Nov 2026 02:20:15 +0000
Message-ID: <E1xW2cI-00000000D0S-2H59@gemulon.postgresql.org> (raw)

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@sss.pgh.pa.us>
Backpatch-through: 15

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e2b5126f8f6d90870be01621378c5d84b93fd948

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(-)



view thread (6+ messages)

Message-ID: <E1xW2cI-00000000D0S-2H59@gemulon.postgresql.org>
Permalink:  ../E1xW2cI-00000000D0S-2H59@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xW2cI-00000000D0S-2H59@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Avoid null pointer crash after pg_localtime()/pg_gmtime() failur
  In-Reply-To: <E1xW2cI-00000000D0S-2H59@gemulon.postgresql.org>
  References: <E1xW2cI-00000000D0S-2H59@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox