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 PQescapeLiteral()/PQescapeIdentifier() length handling
Date: Fri, 14 Feb 2025 23:51:42 +0000
Message-ID: <E1tj5TC-007ATb-CE@gemulon.postgresql.org> (raw)

Fix PQescapeLiteral()/PQescapeIdentifier() length handling

In 5dc1e42b4fa I fixed bugs in various escape functions, unfortunately as part
of that I introduced a new bug in PQescapeLiteral()/PQescapeIdentifier(). The
bug is that I made PQescapeInternal() just use strlen(), rather than taking
the specified input length into account.

That's bad, because it can lead to including input that wasn't intended to be
included (in case len is shorter than null termination of the string) and
because it can lead to reading invalid memory if the input string is not null
terminated.

Expand test_escape to this kind of bug:

a) for escape functions with length support, append data that should not be
   escaped and check that it is not

b) add valgrind requests to detect access of bytes that should not be touched

Author: Tom Lane <tgl@sss.pgh.pa.us>
Author: Andres Freund <andres@anarazel.de
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Noah Misch <noah@leadboat.com>
Discussion: https://postgr.es/m/Z64jD3u46gObCo1p@pryzbyj2023
Backpatch: 13

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/111f4dd273c840426d296c3b2ed0c5c67e3f4c37

Modified Files
--------------
src/interfaces/libpq/fe-exec.c             |  4 +-
src/test/modules/test_escape/test_escape.c | 78 ++++++++++++++++++++++++++++--
2 files changed, 77 insertions(+), 5 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1tj5TC-007ATb-CE@gemulon.postgresql.org>
Permalink:  ../E1tj5TC-007ATb-CE@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1tj5TC-007ATb-CE@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 PQescapeLiteral()/PQescapeIdentifier() length handling
  In-Reply-To: <E1tj5TC-007ATb-CE@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