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 <[email protected]> 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(-)
