pgsql: Make escaping functions retain trailing bytes of an invalid char

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Make escaping functions retain trailing bytes of an invalid char
Date: 2025-02-15 21:20:49
Message-ID: E1tjPai-007Ji8-VF@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make escaping functions retain trailing bytes of an invalid character.

Instead of dropping the trailing byte(s) of an invalid or incomplete
multibyte character, replace only the first byte with a known-invalid
sequence, and process the rest normally. This seems less likely to
confuse incautious callers than the behavior adopted in 5dc1e42b4.

While we're at it, adjust PQescapeStringInternal to produce at most
one bleat about invalid multibyte characters per string. This
matches the behavior of PQescapeInternal, and avoids the risk of
producing tons of repetitive junk if a long string is simply given
in the wrong encoding.

This is a followup to the fixes for CVE-2025-1094, and should be
included if cherry-picking those fixes.

Author: Andres Freund <andres(at)anarazel(dot)de>
Co-authored-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Reported-by: Jeff Davis <pgsql(at)j-davis(dot)com>
Discussion: https://postgr.es/m/20250215012712.45@rfd.leadboat.com
Backpatch-through: 13

Branch
------
REL_15_STABLE

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

Modified Files
--------------
src/fe_utils/string_utils.c | 91 ++++++++++++++++--------------------------
src/interfaces/libpq/fe-exec.c | 73 +++++++++++++++------------------
2 files changed, 67 insertions(+), 97 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2025-02-16 17:46:52 pgsql: In fmtIdEnc(), handle failure of enlargePQExpBuffer().
Previous Message Thomas Munro 2025-02-15 00:17:26 pgsql: Fix explicit valgrind interaction in read_stream.c.