pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Make escaping functions retain trailing bytes of an invalid char
8+ messages / 2 participants
[nested] [flat]
Commits from this thread:
2025-05-01 06a2c598e1 87af12e71f 715241d71f Add missing newlines to PQescapeInternal() messages pre-v16.
* pgsql: Make escaping functions retain trailing bytes of an invalid char
@ 2025-02-15 21:20 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2025-02-15 21:20 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Make escaping functions retain trailing bytes of an invalid character.
Instead of dropping the trailing byte(s) of an invalid or incomplete
multibyte character, replace only the first byte with a known-invalid
sequence, and process the rest normally. This seems less likely to
confuse incautious callers than the behavior adopted in 5dc1e42b4.
While we're at it, adjust PQescapeStringInternal to produce at most
one bleat about invalid multibyte characters per string. This
matches the behavior of PQescapeInternal, and avoids the risk of
producing tons of repetitive junk if a long string is simply given
in the wrong encoding.
This is a followup to the fixes for CVE-2025-1094, and should be
included if cherry-picking those fixes.
Author: Andres Freund <andres@anarazel.de>
Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
Reported-by: Jeff Davis <pgsql@j-davis.com>
Discussion: https://postgr.es/m/20250215012712.45@rfd.leadboat.com
Backpatch-through: 13
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/9f45e6a91d8460ac0b1f30e6ae3eefb185b8d0ab
Modified Files
--------------
src/fe_utils/string_utils.c | 91 ++++++++++++++++--------------------------
src/interfaces/libpq/fe-exec.c | 69 ++++++++++++++------------------
2 files changed, 65 insertions(+), 95 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Make escaping functions retain trailing bytes of an invalid char
@ 2025-02-15 21:20 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2025-02-15 21:20 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Make escaping functions retain trailing bytes of an invalid character.
Instead of dropping the trailing byte(s) of an invalid or incomplete
multibyte character, replace only the first byte with a known-invalid
sequence, and process the rest normally. This seems less likely to
confuse incautious callers than the behavior adopted in 5dc1e42b4.
While we're at it, adjust PQescapeStringInternal to produce at most
one bleat about invalid multibyte characters per string. This
matches the behavior of PQescapeInternal, and avoids the risk of
producing tons of repetitive junk if a long string is simply given
in the wrong encoding.
This is a followup to the fixes for CVE-2025-1094, and should be
included if cherry-picking those fixes.
Author: Andres Freund <andres@anarazel.de>
Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
Reported-by: Jeff Davis <pgsql@j-davis.com>
Discussion: https://postgr.es/m/20250215012712.45@rfd.leadboat.com
Backpatch-through: 13
Branch
------
REL_17_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/3abe6e04cc69d1076a695d90e179dd64010a2667
Modified Files
--------------
src/fe_utils/string_utils.c | 91 ++++++++++++++++--------------------------
src/interfaces/libpq/fe-exec.c | 69 ++++++++++++++------------------
2 files changed, 65 insertions(+), 95 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Make escaping functions retain trailing bytes of an invalid char
@ 2025-02-15 21:20 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2025-02-15 21:20 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Make escaping functions retain trailing bytes of an invalid character.
Instead of dropping the trailing byte(s) of an invalid or incomplete
multibyte character, replace only the first byte with a known-invalid
sequence, and process the rest normally. This seems less likely to
confuse incautious callers than the behavior adopted in 5dc1e42b4.
While we're at it, adjust PQescapeStringInternal to produce at most
one bleat about invalid multibyte characters per string. This
matches the behavior of PQescapeInternal, and avoids the risk of
producing tons of repetitive junk if a long string is simply given
in the wrong encoding.
This is a followup to the fixes for CVE-2025-1094, and should be
included if cherry-picking those fixes.
Author: Andres Freund <andres@anarazel.de>
Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
Reported-by: Jeff Davis <pgsql@j-davis.com>
Discussion: https://postgr.es/m/20250215012712.45@rfd.leadboat.com
Backpatch-through: 13
Branch
------
REL_16_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/991a60a9f23bd2b160e223c46bb2ae1db58f738a
Modified Files
--------------
src/fe_utils/string_utils.c | 91 ++++++++++++++++--------------------------
src/interfaces/libpq/fe-exec.c | 69 ++++++++++++++------------------
2 files changed, 65 insertions(+), 95 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Make escaping functions retain trailing bytes of an invalid char
@ 2025-02-15 21:20 Tom Lane <tgl@sss.pgh.pa.us>
2025-05-01 21:04 ` Re: pgsql: Make escaping functions retain trailing bytes of an invalid char Peter Eisentraut <peter@eisentraut.org>
0 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2025-02-15 21:20 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Make escaping functions retain trailing bytes of an invalid character.
Instead of dropping the trailing byte(s) of an invalid or incomplete
multibyte character, replace only the first byte with a known-invalid
sequence, and process the rest normally. This seems less likely to
confuse incautious callers than the behavior adopted in 5dc1e42b4.
While we're at it, adjust PQescapeStringInternal to produce at most
one bleat about invalid multibyte characters per string. This
matches the behavior of PQescapeInternal, and avoids the risk of
producing tons of repetitive junk if a long string is simply given
in the wrong encoding.
This is a followup to the fixes for CVE-2025-1094, and should be
included if cherry-picking those fixes.
Author: Andres Freund <andres@anarazel.de>
Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
Reported-by: Jeff Davis <pgsql@j-davis.com>
Discussion: https://postgr.es/m/20250215012712.45@rfd.leadboat.com
Backpatch-through: 13
Branch
------
REL_15_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/e782a63ccb76a8db476abb8f5d96397806e3e51b
Modified Files
--------------
src/fe_utils/string_utils.c | 91 ++++++++++++++++--------------------------
src/interfaces/libpq/fe-exec.c | 73 +++++++++++++++------------------
2 files changed, 67 insertions(+), 97 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Make escaping functions retain trailing bytes of an invalid char
2025-02-15 21:20 pgsql: Make escaping functions retain trailing bytes of an invalid char Tom Lane <tgl@sss.pgh.pa.us>
@ 2025-05-01 21:04 ` Peter Eisentraut <peter@eisentraut.org>
2025-05-01 21:15 ` Re: pgsql: Make escaping functions retain trailing bytes of an invalid char Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 8+ messages in thread
From: Peter Eisentraut @ 2025-05-01 21:04 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-committers@lists.postgresql.org
On 15.02.25 22:20, Tom Lane wrote:
> Make escaping functions retain trailing bytes of an invalid character.
>
> Instead of dropping the trailing byte(s) of an invalid or incomplete
> multibyte character, replace only the first byte with a known-invalid
> sequence, and process the rest normally. This seems less likely to
> confuse incautious callers than the behavior adopted in 5dc1e42b4.
>
> While we're at it, adjust PQescapeStringInternal to produce at most
> one bleat about invalid multibyte characters per string. This
> matches the behavior of PQescapeInternal, and avoids the risk of
> producing tons of repetitive junk if a long string is simply given
> in the wrong encoding.
>
> This is a followup to the fixes for CVE-2025-1094, and should be
> included if cherry-picking those fixes.
>
> Author: Andres Freund <andres@anarazel.de>
> Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
> Reported-by: Jeff Davis <pgsql@j-davis.com>
> Discussion: https://postgr.es/m/20250215012712.45@rfd.leadboat.com
> Backpatch-through: 13
>
> Branch
> ------
> REL_15_STABLE
>
> Details
> -------
> https://git.postgresql.org/pg/commitdiff/e782a63ccb76a8db476abb8f5d96397806e3e51b
>
> Modified Files
> --------------
> src/fe_utils/string_utils.c | 91 ++++++++++++++++--------------------------
> src/interfaces/libpq/fe-exec.c | 73 +++++++++++++++------------------
> 2 files changed, 67 insertions(+), 97 deletions(-)
I think the backpatch of this to PG15 and older has erroneously dropped
newlines at the end of some error messages. (libpq in newer PG uses
libpq_append_conn_error() etc. and does not have newlines in error
message strings anymore.) I think this fix would be appropriate for
PG15 and older:
inline patch 1: src/interfaces/libpq/fe-exec.c (+2/-2 lines) download inline-1.patch
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 4a4731d048c..73c3a0f9025 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -4040,10 +4040,10 @@ PQescapeStringInternal(PGconn *conn,
{
if (remaining < charlen)
appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("incomplete multibyte character"));
+ libpq_gettext("incomplete multibyte character\n"));
else
appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("invalid multibyte character"));
+ libpq_gettext("invalid multibyte character\n"));
/* Issue a complaint only once per string */
already_complained = true;
}
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: pgsql: Make escaping functions retain trailing bytes of an invalid char
2025-02-15 21:20 pgsql: Make escaping functions retain trailing bytes of an invalid char Tom Lane <tgl@sss.pgh.pa.us>
2025-05-01 21:04 ` Re: pgsql: Make escaping functions retain trailing bytes of an invalid char Peter Eisentraut <peter@eisentraut.org>
@ 2025-05-01 21:15 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2025-05-01 21:15 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: pgsql-committers@lists.postgresql.org
Peter Eisentraut <peter@eisentraut.org> writes:
> On 15.02.25 22:20, Tom Lane wrote:
>> Make escaping functions retain trailing bytes of an invalid character.
> I think the backpatch of this to PG15 and older has erroneously dropped
> newlines at the end of some error messages.
Oh! You're right, though I'd phrase it differently: I should have
*added* newlines when back-patching into those branches. Will fix.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Make escaping functions retain trailing bytes of an invalid char
@ 2025-02-15 21:20 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2025-02-15 21:20 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Make escaping functions retain trailing bytes of an invalid character.
Instead of dropping the trailing byte(s) of an invalid or incomplete
multibyte character, replace only the first byte with a known-invalid
sequence, and process the rest normally. This seems less likely to
confuse incautious callers than the behavior adopted in 5dc1e42b4.
While we're at it, adjust PQescapeStringInternal to produce at most
one bleat about invalid multibyte characters per string. This
matches the behavior of PQescapeInternal, and avoids the risk of
producing tons of repetitive junk if a long string is simply given
in the wrong encoding.
This is a followup to the fixes for CVE-2025-1094, and should be
included if cherry-picking those fixes.
Author: Andres Freund <andres@anarazel.de>
Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
Reported-by: Jeff Davis <pgsql@j-davis.com>
Discussion: https://postgr.es/m/20250215012712.45@rfd.leadboat.com
Backpatch-through: 13
Branch
------
REL_14_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/c08309584ac58a28072fa2c4765fb4c4c01a901d
Modified Files
--------------
src/fe_utils/string_utils.c | 91 ++++++++++++++++--------------------------
src/interfaces/libpq/fe-exec.c | 73 +++++++++++++++------------------
2 files changed, 67 insertions(+), 97 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
* pgsql: Make escaping functions retain trailing bytes of an invalid char
@ 2025-02-15 21:20 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2025-02-15 21:20 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Make escaping functions retain trailing bytes of an invalid character.
Instead of dropping the trailing byte(s) of an invalid or incomplete
multibyte character, replace only the first byte with a known-invalid
sequence, and process the rest normally. This seems less likely to
confuse incautious callers than the behavior adopted in 5dc1e42b4.
While we're at it, adjust PQescapeStringInternal to produce at most
one bleat about invalid multibyte characters per string. This
matches the behavior of PQescapeInternal, and avoids the risk of
producing tons of repetitive junk if a long string is simply given
in the wrong encoding.
This is a followup to the fixes for CVE-2025-1094, and should be
included if cherry-picking those fixes.
Author: Andres Freund <andres@anarazel.de>
Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
Reported-by: Jeff Davis <pgsql@j-davis.com>
Discussion: https://postgr.es/m/20250215012712.45@rfd.leadboat.com
Backpatch-through: 13
Branch
------
REL_13_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/d6d29b2133f1c2a7d4f332bf68b2f40c8de3044c
Modified Files
--------------
src/fe_utils/string_utils.c | 91 ++++++++++++++++--------------------------
src/interfaces/libpq/fe-exec.c | 73 +++++++++++++++------------------
2 files changed, 67 insertions(+), 97 deletions(-)
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2025-05-01 21:15 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-02-15 21:20 pgsql: Make escaping functions retain trailing bytes of an invalid char Tom Lane <tgl@sss.pgh.pa.us>
2025-02-15 21:20 pgsql: Make escaping functions retain trailing bytes of an invalid char Tom Lane <tgl@sss.pgh.pa.us>
2025-02-15 21:20 pgsql: Make escaping functions retain trailing bytes of an invalid char Tom Lane <tgl@sss.pgh.pa.us>
2025-02-15 21:20 pgsql: Make escaping functions retain trailing bytes of an invalid char Tom Lane <tgl@sss.pgh.pa.us>
2025-05-01 21:04 ` Peter Eisentraut <peter@eisentraut.org>
2025-05-01 21:15 ` Tom Lane <tgl@sss.pgh.pa.us>
2025-02-15 21:20 pgsql: Make escaping functions retain trailing bytes of an invalid char Tom Lane <tgl@sss.pgh.pa.us>
2025-02-15 21:20 pgsql: Make escaping functions retain trailing bytes of an invalid char Tom Lane <tgl@sss.pgh.pa.us>
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