postgres/src/common
Andrew Dunstan 5c32c21afe jsonapi: add lexer option to keep token ownership
Commit 0785d1b8b adds support for libpq as a JSON client, but
allocations for string tokens can still be leaked during parsing
failures. This is tricky to fix for the object_field semantic callbacks:
the field name must remain valid until the end of the object, but if a
parsing error is encountered partway through, object_field_end() won't
be invoked and the client won't get a chance to free the field name.

This patch adds a flag to switch the ownership of parsed tokens to the
lexer. When this is enabled, the client must make a copy of any tokens
it wants to persist past the callback lifetime, but the lexer will
handle necessary cleanup on failure.

Backend uses of the JSON parser don't need to use this flag, since the
parser's allocations will occur in a short lived memory context.

A -o option has been added to test_json_parser_incremental to exercise
the new setJsonLexContextOwnsTokens() API, and the test_json_parser TAP
tests make use of it. (The test program now cleans up allocated memory,
so that tests can be usefully run under leak sanitizers.)

Author: Jacob Champion

Discussion: https://postgr.es/m/CAOYmi+kb38EciwyBQOf9peApKGwraHqA7pgzBkvoUnw5BRfS1g@mail.gmail.com
2024-11-27 12:07:14 -05:00
..
unicode Clean up newlines following left parentheses 2024-11-26 17:10:07 +01:00
.gitignore
archive.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
base64.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
binaryheap.c Optimize sifting down in binaryheap. 2024-10-30 11:28:34 -05:00
blkreftable.c Fix incorrect calculation in BlockRefTableEntryGetBlocks. 2024-04-05 13:41:19 -04:00
checksum_helper.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
compression.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
config_info.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
controldata_utils.c Remove unused #include's from bin .c files 2024-11-06 11:11:52 +01:00
cryptohash_openssl.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
cryptohash.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
d2s_full_table.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
d2s_intrinsics.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
d2s.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
digit_table.h Change floating-point output format for improved performance. 2019-02-13 15:20:33 +00:00
encnames.c Simplify pg_enc2gettext_tbl[] with C99-designated initializer syntax 2024-03-01 18:03:48 +09:00
exec.c Remove support for old realpath() API 2024-08-12 08:04:35 +02:00
f2s.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
fe_memutils.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
file_perm.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
file_utils.c Define PG_TBLSPC_DIR for path pg_tblspc/ in data folder 2024-09-03 09:11:54 +09:00
hashfn.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
hmac_openssl.c Remove support for OpenSSL older than 1.1.0 2024-09-02 13:51:48 +02:00
hmac.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
ip.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
jsonapi.c jsonapi: add lexer option to keep token ownership 2024-11-27 12:07:14 -05:00
keywords.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
kwlookup.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
link-canary.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
logging.c Fix memory leaks from incorrect strsep() uses 2024-10-18 11:29:20 +02:00
Makefile common/jsonapi: support libpq as a client 2024-09-11 09:01:07 +02:00
md5_common.c Fix documentation comment for pg_md5_hash 2024-03-14 09:23:37 +01:00
md5_int.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
md5.c Make fallback MD5 implementation thread-safe on big-endian systems 2024-08-07 10:43:52 +03:00
meson.build common/jsonapi: support libpq as a client 2024-09-11 09:01:07 +02:00
parse_manifest.c Clean up newlines following left parentheses 2024-11-26 17:10:07 +01:00
percentrepl.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_get_line.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_lzcompress.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_prng.c Add functions to generate random numbers in a specified range. 2024-03-27 10:12:39 +00:00
pgfnames.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
psprintf.c Unify src/common/'s definitions of MaxAllocSize. 2024-10-28 14:39:01 -04:00
relpath.c Define PG_TBLSPC_DIR for path pg_tblspc/ in data folder 2024-09-03 09:11:54 +09:00
restricted_token.c Convert some extern variables to static, Windows code 2024-08-01 13:28:32 +02:00
rmtree.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
ryu_common.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
saslprep.c Unify src/common/'s definitions of MaxAllocSize. 2024-10-28 14:39:01 -04:00
scram-common.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
sha1_int.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
sha1.c Mark misc static global variables as const 2024-08-06 23:04:48 +03:00
sha2_int.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
sha2.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
sprompt.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
string.c Remove unused #include's from bin .c files 2024-11-06 11:11:52 +01:00
stringinfo.c Unify src/common/'s definitions of MaxAllocSize. 2024-10-28 14:39:01 -04:00
unicode_case.c Remove unused #include's from bin .c files 2024-11-06 11:11:52 +01:00
unicode_category.c Pre-beta mechanical code beautification. 2024-05-14 16:34:50 -04:00
unicode_norm.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
username.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
wait_error.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
wchar.c Inline basic UTF-8 functions. 2024-03-20 09:40:57 -07:00