aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-exec.c
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2025-05-05 04:52:04 -0700
committerNoah Misch <noah@leadboat.com>2025-05-05 04:52:04 -0700
commit627acc3caa74caa736b2c5587e944d2ea510ea67 (patch)
tree7aed8aec94c841de34fad669bd8b4376ff15c1a3 /src/interfaces/libpq/fe-exec.c
parent5be213caaa1a9a65dfdbbf400b6a53b5e743b8d1 (diff)
downloadpostgresql-627acc3caa74caa736b2c5587e944d2ea510ea67.tar.gz
postgresql-627acc3caa74caa736b2c5587e944d2ea510ea67.zip
With GB18030, prevent SIGSEGV from reading past end of allocation.
With GB18030 as source encoding, applications could crash the server via SQL functions convert() or convert_from(). Applications themselves could crash after passing unterminated GB18030 input to libpq functions PQescapeLiteral(), PQescapeIdentifier(), PQescapeStringConn(), or PQescapeString(). Extension code could crash by passing unterminated GB18030 input to jsonapi.h functions. All those functions have been intended to handle untrusted, unterminated input safely. A crash required allocating the input such that the last byte of the allocation was the last byte of a virtual memory page. Some malloc() implementations take measures against that, making the SIGSEGV hard to reach. Back-patch to v13 (all supported versions). Author: Noah Misch <noah@leadboat.com> Author: Andres Freund <andres@anarazel.de> Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com> Backpatch-through: 13 Security: CVE-2025-4207
Diffstat (limited to 'src/interfaces/libpq/fe-exec.c')
-rw-r--r--src/interfaces/libpq/fe-exec.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 294843ed8b0..4256ae5c0cc 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -4101,7 +4101,8 @@ PQescapeStringInternal(PGconn *conn,
}
/* Slow path for possible multibyte characters */
- charlen = pg_encoding_mblen(encoding, source);
+ charlen = pg_encoding_mblen_or_incomplete(encoding,
+ source, remaining);
if (remaining < charlen ||
pg_encoding_verifymbchar(encoding, source, charlen) == -1)
@@ -4245,7 +4246,8 @@ PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident)
int charlen;
/* Slow path for possible multibyte characters */
- charlen = pg_encoding_mblen(conn->client_encoding, s);
+ charlen = pg_encoding_mblen_or_incomplete(conn->client_encoding,
+ s, remaining);
if (charlen > remaining)
{