pgsql: With GB18030, prevent SIGSEGV from reading past end of allocatio

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: With GB18030, prevent SIGSEGV from reading past end of allocatio
Date: 2025-05-05 11:52:35
Message-ID: E1uBuN8-000FUg-23@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)leadboat(dot)com>
Author: Andres Freund <andres(at)anarazel(dot)de>
Reviewed-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Backpatch-through: 13
Security: CVE-2025-4207

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/627acc3caa74caa736b2c5587e944d2ea510ea67

Modified Files
--------------
src/backend/utils/mb/mbutils.c | 18 ++++--
src/common/jsonapi.c | 7 ++-
src/common/wchar.c | 51 ++++++++++++++--
src/include/mb/pg_wchar.h | 2 +
src/interfaces/libpq/fe-exec.c | 6 +-
src/interfaces/libpq/fe-misc.c | 15 ++---
src/test/modules/test_escape/test_escape.c | 96 ++++++++++++++++++++++++++++++
src/test/regress/expected/conversion.out | 13 ++--
src/test/regress/sql/conversion.sql | 7 ++-
9 files changed, 185 insertions(+), 30 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2025-05-05 14:57:52 Re: pgsql: Add function to log the memory contexts of specified backend pro
Previous Message Peter Eisentraut 2025-05-05 10:30:37 pgsql: Translation updates