postgresql/src/backend/utils/adt
Tom Lane b0feda79fd Fix jsonb subscripting to cope with toasted subscript values.
jsonb_get_element() was incautious enough to use VARDATA() and
VARSIZE() directly on an arbitrary text Datum.  That of course
fails if the Datum is short-header, compressed, or out-of-line.
The typical result would be failing to match any element of a
jsonb object, though matching the wrong one seems possible as well.

setPathObject() was slightly brighter, in that it used VARDATA_ANY
and VARSIZE_ANY_EXHDR, but that only kept it out of trouble for
short-header Datums.  push_path() had the same issue.  This could
result in faulty subscripted insertions, though keys long enough to
cause a problem are likely rare in the wild.

Having seen these, I looked around for unsafe usages in the rest
of the adt/json* files.  There are a couple of places where it's not
immediately obvious that the Datum can't be compressed or out-of-line,
so I added pg_detoast_datum_packed() to cope if it is.  Also, remove
some other usages of VARDATA/VARSIZE on Datums we just extracted from
a text array.  Those aren't actively broken, but they will become so
if we ever start allowing short-header array elements, which does not
seem like a terribly unreasonable thing to do.  In any case they are
not great coding examples, and they could also do with comments
pointing out that we're assuming we don't need pg_detoast_datum_packed.

Per report from exe-dealer@yandex.ru.  Patch by me, but thanks to
David Johnston for initial investigation.  Back-patch to v14 where
jsonb subscripting was introduced.

Discussion: https://postgr.es/m/205321670615953@mail.yandex.ru
2022-12-12 16:17:54 -05:00
..
.gitignore Build all Flex files standalone 2022-09-04 12:09:01 +07:00
acl.c Provide per-table permissions for vacuum and analyze. 2022-11-28 12:08:14 -05:00
amutils.c Fix incorrect uses of Datum conversion macros 2022-09-05 13:30:44 +02:00
array_expanded.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
array_selfuncs.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
array_typanalyze.c Rename shadowed local variables 2022-10-05 21:01:41 +13:00
array_userfuncs.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
arrayfuncs.c Convert a few datatype input functions to use "soft" error reporting. 2022-12-09 10:14:53 -05:00
arraysubs.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
arrayutils.c Convert a few datatype input functions to use "soft" error reporting. 2022-12-09 10:14:53 -05:00
ascii.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
bool.c Convert a few datatype input functions to use "soft" error reporting. 2022-12-09 10:14:53 -05:00
cash.c Remove unused includes 2021-12-01 16:10:56 +01:00
char.c Change type "char"'s I/O format for non-ASCII characters. 2022-08-02 10:29:35 -04:00
cryptohashfuncs.c Improve error handling of cryptohash computations 2022-01-11 09:55:16 +09:00
date.c Convert datetime input functions to use "soft" error reporting. 2022-12-09 16:07:49 -05:00
datetime.c Convert datetime input functions to use "soft" error reporting. 2022-12-09 16:07:49 -05:00
datum.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
dbsize.c Refactor aclcheck functions 2022-11-13 09:02:41 +01:00
domains.c Convert domain_in to report errors softly. 2022-12-11 12:56:54 -05:00
encode.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
enum.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
expandeddatum.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
expandedrecord.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
float.c Convert a few datatype input functions to use "soft" error reporting. 2022-12-09 10:14:53 -05:00
format_type.c Revert SQL/JSON features 2022-09-01 17:07:14 -04:00
formatting.c Restructure soft-error handling in formatting.c. 2022-12-09 20:15:56 -05:00
genfile.c Rename SetSingleFuncCall() to InitMaterializedSRF() 2022-10-18 10:22:35 +09:00
geo_ops.c Convert a few datatype input functions to use "soft" error reporting. 2022-12-09 10:14:53 -05:00
geo_selfuncs.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
geo_spgist.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
hbafuncs.c Add support for file inclusions in HBA and ident configuration files 2022-11-24 13:51:34 +09:00
inet_cidr_ntop.c
inet_net_pton.c
int8.c Convert a few datatype input functions to use "soft" error reporting. 2022-12-09 10:14:53 -05:00
int.c Convert a few datatype input functions to use "soft" error reporting. 2022-12-09 10:14:53 -05:00
json.c Convert json_in and jsonb_in to report errors softly. 2022-12-11 11:28:15 -05:00
jsonb_gin.c Fix jsonb subscripting to cope with toasted subscript values. 2022-12-12 16:17:54 -05:00
jsonb_op.c Fix jsonb subscripting to cope with toasted subscript values. 2022-12-12 16:17:54 -05:00
jsonb_util.c Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
jsonb.c Convert json_in and jsonb_in to report errors softly. 2022-12-11 11:28:15 -05:00
jsonbsubs.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
jsonfuncs.c Fix jsonb subscripting to cope with toasted subscript values. 2022-12-12 16:17:54 -05:00
jsonpath_exec.c Restructure soft-error handling in formatting.c. 2022-12-09 20:15:56 -05:00
jsonpath_gram.y Suppress variable-set-but-not-used warnings from clang 15. 2022-09-20 12:04:37 -04:00
jsonpath_internal.h Build all Flex files standalone 2022-09-04 12:09:01 +07:00
jsonpath_scan.l Harmonize more lexer function parameter names. 2022-09-22 13:27:16 -07:00
jsonpath.c Revert SQL/JSON features 2022-09-01 17:07:14 -04:00
levenshtein.c Further -Wshadow=compatible-local warning fixes 2022-08-24 22:04:28 +12:00
like_match.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
like_support.c Defend against stack overrun in a few more places. 2022-08-24 13:02:19 -04:00
like.c Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
lockfuncs.c Replace many MemSet calls with struct initialization 2022-07-16 08:50:49 +02:00
mac8.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
mac.c Specialize tuplesort routines for different kinds of abbreviated keys 2022-04-02 15:22:25 +07:00
Makefile Build all Flex files standalone 2022-09-04 12:09:01 +07:00
mcxtfuncs.c Remove AssertArg and AssertState 2022-10-28 09:19:06 +02:00
meson.build meson: Add initial version of meson based build system 2022-09-21 22:37:17 -07:00
misc.c Add test scaffolding for soft error reporting from input functions. 2022-12-09 10:08:44 -05:00
multirangetypes_selfuncs.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
multirangetypes.c Fix incorrect uses of Datum conversion macros 2022-09-05 13:30:44 +02:00
name.c Add construct_array_builtin, deconstruct_array_builtin 2022-07-01 11:23:15 +02:00
network_gist.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
network_selfuncs.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
network_spgist.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
network.c Remove configure probe for sockaddr_in6 and require AF_INET6. 2022-08-26 10:18:30 +12:00
numeric.c Convert a few datatype input functions to use "soft" error reporting. 2022-12-09 10:14:53 -05:00
numutils.c Convert a few datatype input functions to use "soft" error reporting. 2022-12-09 10:14:53 -05:00
oid.c Rename value node fields 2022-01-14 11:26:08 +01:00
oracle_compat.c Avoid ERRCODE_INTERNAL_ERROR in oracle_compat.c functions. 2022-05-26 12:25:10 -04:00
orderedsetaggs.c Allow nodeSort to perform Datum sorts for byref types 2022-10-28 09:25:12 +13:00
partitionfuncs.c Rename shadowed local variables 2022-10-05 21:01:41 +13:00
pg_locale.c Split up guc.c for better build speed and ease of maintenance. 2022-09-13 11:11:45 -04:00
pg_lsn.c Fix incorrect uses of Datum conversion macros 2022-09-05 13:30:44 +02:00
pg_upgrade_support.c Revert 56-bit relfilenode change and follow-up commits. 2022-09-28 09:55:28 -04:00
pgstatfuncs.c Fix macro definitions in pgstatfuncs.c 2022-12-10 13:28:02 +09:00
pseudotypes.c Use the macro, not handwritten code, to construct anymultirange_in(). 2022-12-10 17:22:16 -05:00
quote.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
rangetypes_gist.c Remove unnecessary uses of Abs() 2022-10-07 13:29:33 +02:00
rangetypes_selfuncs.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
rangetypes_spgist.c Fix incorrect uses of Datum conversion macros 2022-09-05 13:30:44 +02:00
rangetypes_typanalyze.c Invent qsort_interruptible(). 2022-07-12 16:30:36 -04:00
rangetypes.c Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
regexp.c Consistently use named parameters in regex code. 2022-09-19 15:10:24 -07:00
regproc.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
ri_triggers.c Rework query relation permission checking 2022-12-06 16:09:24 +01:00
rowtypes.c Convert a few datatype input functions to use "soft" error reporting. 2022-12-09 10:14:53 -05:00
ruleutils.c Fix psql's \sf and \ef for new-style SQL functions. 2022-12-02 14:24:44 -05:00
selfuncs.c Re-pgindent a few files. 2022-12-04 14:25:53 -05:00
tid.c Tighten overflow checks in tidin(). 2022-03-03 20:04:35 -05:00
timestamp.c Convert datetime input functions to use "soft" error reporting. 2022-12-09 16:07:49 -05:00
trigfuncs.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
tsginidx.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
tsgistidx.c Standardize error reports in unimplemented I/O functions. 2022-12-10 18:26:43 -05:00
tsquery_cleanup.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
tsquery_gist.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
tsquery_op.c Fix incorrect uses of Datum conversion macros 2022-09-05 13:30:44 +02:00
tsquery_rewrite.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
tsquery_util.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
tsquery.c Introduce t_isalnum() to replace t_isalpha() || t_isdigit() tests. 2022-10-06 11:08:56 -04:00
tsrank.c Remove unnecessary uses of Abs() 2022-10-07 13:29:33 +02:00
tsvector_op.c Add comments and a missing CHECK_FOR_INTERRUPTS in ts_headline. 2022-11-21 17:07:29 -05:00
tsvector_parser.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
tsvector.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
uuid.c Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
varbit.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
varchar.c Fix broken hash function hashbpcharextended(). 2022-12-02 14:06:31 -08:00
varlena.c Rename SetSingleFuncCall() to InitMaterializedSRF() 2022-10-18 10:22:35 +09:00
version.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
windowfuncs.c Teach planner and executor about monotonic window funcs 2022-04-08 10:34:36 +12:00
xid8funcs.c Fix visibility check when XID is committed in CLOG but not in procarray. 2022-06-27 08:21:08 +03:00
xid.c Add min() and max() aggregates for xid8. 2022-02-10 12:33:41 +09:00
xml.c Clean up some inconsistencies with GUC declarations 2022-10-31 12:44:48 +09:00