From: Tom Lane <tgl@sss.pgh.pa.us>
To: anisimow.d@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17816: Invalid memory access in translate function
Date: Wed, 01 Mar 2023 10:46:10 -0500
Message-ID: <1399976.1677685570@sss.pgh.pa.us> (raw)
In-Reply-To: <17816-70f3d2764e88a108@postgresql.org>
References: <17816-70f3d2764e88a108@postgresql.org>
PG Bug reporting form <noreply@postgresql.org> writes:
> When running this query in psql with valgrind-enabled server:
> select translate('(123)', '()', '');
> I get:
> ==00:00:00:05.576 29520== Invalid read of size 1
> ==00:00:00:05.576 29520== at 0x7605BE: pg_utf_mblen (wchar.c:553)
> ==00:00:00:05.576 29520== by 0x71CEDE: pg_mblen (mbutils.c:968)
> ==00:00:00:05.576 29520== by 0x67B1E3: translate (oracle_compat.c:864)
Thanks for the report!
> These changes fix the issue:
> for (i = 0; i < from_index; i++)
> {
> if (p >= (to_ptr + tolen))
> break;
> p += pg_mblen(p);
> }
Yeah, I agree, we need to switch the order of those two statements.
Will fix.
(Might be worth pulling out the common subexpression here?
I wonder if all compilers are smart enough to evaluate to_ptr + to_len
just once.)
regards, tom lane
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-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, anisimow.d@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17816: Invalid memory access in translate function
In-Reply-To: <1399976.1677685570@sss.pgh.pa.us>
* 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