postgresql/contrib/intarray
Tom Lane c0887b39dc Harden _int_matchsel() against being attached to the wrong operator.
While the preceding commit prevented such attachments from occurring
in future, this one aims to prevent further abuse of any already-
created operator that exposes _int_matchsel to the wrong data types.
(No other contrib module has a vulnerable selectivity estimator.)

We need only check that the Const we've found in the query is indeed
of the type we expect (query_int), but there's a difficulty: as an
extension type, query_int doesn't have a fixed OID that we could
hard-code into the estimator.

Therefore, the bulk of this patch consists of infrastructure to let
an extension function securely look up the OID of a datatype
belonging to the same extension.  (Extension authors have requested
such functionality before, so we anticipate that this code will
have additional non-security uses, and may soon be extended to allow
looking up other kinds of SQL objects.)

This is done by first finding the extension that owns the calling
function (there can be only one), and then thumbing through the
objects owned by that extension to find a type that has the desired
name.  This is relatively expensive, especially for large extensions,
so a simple cache is put in front of these lookups.

Reported-by: Daniel Firer as part of zeroday.cloud
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Noah Misch <noah@leadboat.com>
Security: CVE-2026-2004
Backpatch-through: 14
2026-02-09 10:14:22 -05:00
..
bench Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
data Fix integer-overflow problem in intarray's g_int_decompress(). 2024-01-07 15:19:50 -05:00
expected Fix GIN's shimTriConsistentFn to not corrupt its input. 2025-04-12 12:27:46 -04:00
sql Fix GIN's shimTriConsistentFn to not corrupt its input. 2025-04-12 12:27:46 -04:00
.gitignore Support "make check" in contrib 2011-04-25 22:27:11 +03:00
_int.h Fix typos in comments 2023-05-02 12:23:08 +09:00
_int_bool.c Convert contrib/intarray's bqarr_in() to report errors softly 2022-12-28 10:00:12 -05:00
_int_gin.c Make the order of the header file includes consistent in contrib modules. 2019-10-24 08:05:34 +05:30
_int_gist.c Fix integer-overflow problem in intarray's g_int_decompress(). 2024-01-07 15:19:50 -05:00
_int_op.c Clean up newlines following left parentheses 2020-01-30 13:42:14 -03:00
_int_selfuncs.c Harden _int_matchsel() against being attached to the wrong operator. 2026-02-09 10:14:22 -05:00
_int_tool.c Remove useless casts to (void *) in arguments of some system functions 2023-02-07 06:57:59 +01:00
_intbig_gist.c Remove unnecessary pfree() in g_intbig_compress(). 2023-07-13 13:08:08 -04:00
intarray--1.0--1.1.sql Add selectivity estimation functions for intarray operators. 2015-07-21 20:59:24 +03:00
intarray--1.1--1.2.sql Make contrib modules' installation scripts more secure. 2020-08-10 10:44:42 -04:00
intarray--1.2--1.3.sql Implement operator class parameters 2020-03-30 19:17:23 +03:00
intarray--1.2.sql Update extensions with GIN/GIST support for parallel query. 2016-06-14 13:34:37 -04:00
intarray--1.3--1.4.sql Remove <@ from contrib/intarray's GiST operator classes. 2020-08-08 17:26:29 -04:00
intarray--1.4--1.5.sql Remove deprecated containment operators for contrib types. 2021-03-05 10:45:41 -05:00
intarray.control Remove deprecated containment operators for contrib types. 2021-03-05 10:45:41 -05:00
Makefile Remove deprecated containment operators for contrib types. 2021-03-05 10:45:41 -05:00
meson.build Update copyright for 2023 2023-01-02 15:00:37 -05:00