aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-misc.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:08 -0700
commitcbadeaca9271a1bade8ef9790bae09dc92e0ed30 (patch)
tree3d7a9a7b0b36a56d104dbd2b24e58be659f1f387 /src/interfaces/libpq/fe-misc.c
parent7279e58205813305fc09d2cc9977731c05014b84 (diff)
downloadpostgresql-cbadeaca9271a1bade8ef9790bae09dc92e0ed30.tar.gz
postgresql-cbadeaca9271a1bade8ef9790bae09dc92e0ed30.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-misc.c')
-rw-r--r--src/interfaces/libpq/fe-misc.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index 724f1693eec..40500de0425 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -1227,8 +1227,9 @@ pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time)
*/
/*
- * returns the byte length of the character beginning at s, using the
- * specified encoding.
+ * Like pg_encoding_mblen(). Use this in callers that want the
+ * dynamically-linked libpq's stance on encodings, even if that means
+ * different behavior in different startups of the executable.
*/
int
PQmblen(const char *s, int encoding)