mirror of
https://github.com/postgres/postgres.git
synced 2025-08-22 21:53:06 +03:00
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
This commit is contained in:
@@ -3373,7 +3373,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)
|
||||
@@ -3513,7 +3514,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)
|
||||
{
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user