pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid fetching one past the end of translate()'s "to" parameter.
Date: Wed, 01 Mar 2023 16:30:42 +0000
Message-ID: <E1pXPLl-001N4c-Oa@gemulon.postgresql.org> (raw)

Avoid fetching one past the end of translate()'s "to" parameter.

This is usually harmless, but if you were very unlucky it could
provoke a segfault due to the "to" string being right up against
the end of memory.  Found via valgrind testing (so we might've
found it earlier, except that our regression tests lacked any
exercise of translate()'s deletion feature).

Fix by switching the order of the test-for-end-of-string and
advance-pointer steps.  While here, compute "to_ptr + tolen"
just once.  (Smarter compilers might figure that out for
themselves, but let's just make sure.)

Report and fix by Daniil Anisimov, in bug #17816.

Discussion: https://postgr.es/m/17816-70f3d2764e88a108@postgresql.org

Branch
------
REL_12_STABLE

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

Modified Files
--------------
src/backend/utils/adt/oracle_compat.c | 12 +++++++-----
src/test/regress/expected/strings.out |  6 ++++++
src/test/regress/sql/strings.sql      |  1 +
3 files changed, 14 insertions(+), 5 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1pXPLl-001N4c-Oa@gemulon.postgresql.org>
Permalink:  ../E1pXPLl-001N4c-Oa@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1pXPLl-001N4c-Oa@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Avoid fetching one past the end of translate()'s "to" parameter.
  In-Reply-To: <E1pXPLl-001N4c-Oa@gemulon.postgresql.org>
  References: <E1pXPLl-001N4c-Oa@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