pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix handling of invalidly encoded data in escaping functions
Date: Mon, 10 Feb 2025 15:09:49 +0000
Message-ID: <E1thVPw-006NyQ-TY@gemulon.postgresql.org> (raw)

Fix handling of invalidly encoded data in escaping functions

Previously invalidly encoded input to various escaping functions could lead to
the escaped string getting incorrectly parsed by psql.  To be safe, escaping
functions need to ensure that neither invalid nor incomplete multi-byte
characters can be used to "escape" from being quoted.

Functions which can report errors now return an error in more cases than
before. Functions that cannot report errors now replace invalid input bytes
with a byte sequence that cannot be used to escape the quotes and that is
guaranteed to error out when a query is sent to the server.

The following functions are fixed by this commit:
- PQescapeLiteral()
- PQescapeIdentifier()
- PQescapeString()
- PQescapeStringConn()
- fmtId()
- appendStringLiteral()

Reported-by: Stephen Fewer <stephen_fewer@rapid7.com>
Reviewed-by: Noah Misch <noah@leadboat.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Backpatch-through: 13
Security: CVE-2025-1094

Branch
------
REL_14_STABLE

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

Modified Files
--------------
src/fe_utils/string_utils.c    | 170 ++++++++++++++++++++++++++++++++---------
src/interfaces/libpq/fe-exec.c | 135 +++++++++++++++++++++++---------
2 files changed, 237 insertions(+), 68 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1thVPw-006NyQ-TY@gemulon.postgresql.org>
Permalink:  ../E1thVPw-006NyQ-TY@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1thVPw-006NyQ-TY@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix handling of invalidly encoded data in escaping functions
  In-Reply-To: <E1thVPw-006NyQ-TY@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