Re: BUG #17816: Invalid memory access in translate function
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: anisimow.d@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2023-03-01T15:46:10Z
Lists: pgsql-bugs
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
Commits
-
Avoid fetching one past the end of translate()'s "to" parameter.
- d7056bc1c71d 16.0 landed
- eae09137d53e 15.3 landed
- b1a9d8ef254f 11.20 landed
- b162660d3ac4 12.15 landed
- 3b37e844220d 13.11 landed
- 1a9356f657e1 14.8 landed