pgsql: Guard against unsafe conditions in usage of pg_strftime().

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Guard against unsafe conditions in usage of pg_strftime().
Date: 2026-05-11 12:19:37
Message-ID: E1wMPbk-0002T6-2Y@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Guard against unsafe conditions in usage of pg_strftime().

Although pg_strftime() has defined error conditions, no callers bother
to check for errors. This is problematic because the output string is
very likely not null-terminated if an error occurs, so that blindly
using it is unsafe. Rather than trusting that we can find and fix all
the callers, let's alter the function's API spec slightly: make it
guarantee a null-terminated result so long as maxsize > 0.

Furthermore, if we do get an error, let's make that null-terminated
result be an empty string. We could instead truncate at the buffer
length, but that risks producing mis-encoded output if the tz_name
string contains multibyte characters. It doesn't seem reasonable for
src/timezone/ to make use of our encoding-aware truncation logic.
Also, the only really likely source of a failure is a user-supplied
timezone name that is intentionally trying to overrun our buffers.
I don't feel a need to be particularly friendly about that case.

Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Reviewed-by: John Naylor <johncnaylorls(at)gmail(dot)com>
Backpatch-through: 14
Security: CVE-2026-6474

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ec8ded4b327f9d121811f43bf0177d0f289c3949
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>

Modified Files
--------------
src/timezone/strftime.c | 11 +++++++++++
1 file changed, 11 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2026-05-11 12:19:38 pgsql: Harden our regex engine against integer overflow in size calcula
Previous Message Noah Misch 2026-05-11 12:19:36 pgsql: Apply timingsafe_bcmp() in authentication paths