]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Replace pg_mblen() with bounds-checked versions.
authorThomas Munro <tmunro@postgresql.org>
Wed, 7 Jan 2026 09:14:31 +0000 (22:14 +1300)
committerThomas Munro <tmunro@postgresql.org>
Sun, 8 Feb 2026 23:44:04 +0000 (12:44 +1300)
commit1e7fe06c10c0a8da9dd6261a6be8d405dc17c728
tree099841351510e8d019e77e0a0806cf6478e7ea7b
parent74ee636cc93d919c845e3e3ad3642e6366ce1802
Replace pg_mblen() with bounds-checked versions.

A corrupted string could cause code that iterates with pg_mblen() to
overrun its buffer.  Fix, by converting all callers to one of the
following:

1. Callers with a null-terminated string now use pg_mblen_cstr(), which
raises an "illegal byte sequence" error if it finds a terminator in the
middle of the sequence.

2. Callers with a length or end pointer now use either
pg_mblen_with_len() or pg_mblen_range(), for the same effect, depending
on which of the two seems more convenient at each site.

3. A small number of cases pre-validate a string, and can use
pg_mblen_unbounded().

The traditional pg_mblen() function and COPYCHAR macro still exist for
backward compatibility, but are no longer used by core code and are
hereby deprecated.  The same applies to the t_isXXX() functions.

Security: CVE-2026-2006
Backpatch-through: 14
Co-authored-by: Thomas Munro <thomas.munro@gmail.com>
Co-authored-by: Noah Misch <noah@leadboat.com>
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reported-by: Paul Gerste (as part of zeroday.cloud)
Reported-by: Moritz Sanft (as part of zeroday.cloud)
43 files changed:
contrib/btree_gist/btree_utils_var.c
contrib/dict_xsyn/dict_xsyn.c
contrib/hstore/hstore_io.c
contrib/ltree/crc32.c
contrib/ltree/lquery_op.c
contrib/ltree/ltree.h
contrib/ltree/ltree_io.c
contrib/ltree/ltxtquery_io.c
contrib/pageinspect/heapfuncs.c
contrib/pg_trgm/trgm.h
contrib/pg_trgm/trgm_op.c
contrib/pg_trgm/trgm_regexp.c
contrib/pgcrypto/crypt-sha.c
contrib/unaccent/unaccent.c
src/backend/catalog/pg_proc.c
src/backend/tsearch/dict_synonym.c
src/backend/tsearch/dict_thesaurus.c
src/backend/tsearch/regis.c
src/backend/tsearch/spell.c
src/backend/tsearch/ts_locale.c
src/backend/tsearch/ts_utils.c
src/backend/tsearch/wparser_def.c
src/backend/utils/adt/encode.c
src/backend/utils/adt/formatting.c
src/backend/utils/adt/jsonfuncs.c
src/backend/utils/adt/jsonpath_gram.y
src/backend/utils/adt/levenshtein.c
src/backend/utils/adt/like.c
src/backend/utils/adt/like_match.c
src/backend/utils/adt/oracle_compat.c
src/backend/utils/adt/regexp.c
src/backend/utils/adt/tsquery.c
src/backend/utils/adt/tsvector.c
src/backend/utils/adt/tsvector_op.c
src/backend/utils/adt/tsvector_parser.c
src/backend/utils/adt/varbit.c
src/backend/utils/adt/varlena.c
src/backend/utils/adt/xml.c
src/backend/utils/mb/mbutils.c
src/include/mb/pg_wchar.h
src/include/tsearch/ts_locale.h
src/include/tsearch/ts_utils.h
src/test/modules/test_regex/test_regex.c