Repository navigation
Conversation
NormB
force-pushed
the
fix/cachedb-nats-rtld-global
branch
from
November 27, 2026 03:37
8b18a9d to
9a25d67
Compare
NormB
force-pushed
the
fix/cachedb-nats-rtld-global
branch
from
November 27, 2026 04:54
9a25d67 to
3505e4d
Compare
NormB
force-pushed
the
fix/cachedb-nats-rtld-global
branch
from
December 3, 2026 23:19
44a45eb to
295f66d
Compare
cachedb_nats was opened RTLD_NOW | RTLD_GLOBAL so that cachedb_nats_fts
could resolve its hand-written JSON scanners as symbols. RTLD_GLOBAL
also put every other global symbol of cachedb_nats.so in the global
scope, its "struct module_exports exports" included. In a module loaded
after it, a reference to its own "exports" then bound to cachedb_nats's:
rtpengine's notification_sock setter wrote cachedb_nats's exports.procs,
so the "RTPEngine notification receiver" process was never forked.
cachedb_nats_fts's own nats_api bound to cachedb_nats's the same way.
Open cachedb_nats with DEFAULT_DLFLAGS, and have cachedb_nats_fts parse
documents with the core's cJSON (lib/cJSON.h), so that it needs nothing
of cachedb_nats's JSON code.
cachedb_nats_fts therefore no longer has to be loaded after cachedb_nats
(before, loading it first failed on an undefined symbol); the nats and
cachedb_nats_fts READMEs stop saying so.
Field names and values are now indexed decoded ("a\"b" as a"b,
"é" as UTF-8). A document is refused whole, with a warning, when
it is not one JSON object (trailing text included), is malformed, holds
a NUL (raw or \u0000), or exceeds the limits below. cJSON allocates
with the system malloc here, as the index is also used from threads and
pkg memory is not thread-safe.
New cachedb_nats_fts modparams, checked when the config is read (so
opensips -C reports a bad value) and again in mod_init:
json_max_depth nesting limit, default 64, 1..1024 (cJSON recurses
once per level)
json_max_bytes size limit, default 1048576, at least 2
test_index_partial_snapshot passed lengths that counted the C string
terminator; the new parser refuses the NUL, as cachedb_nats's own reader
already does, so the lengths are corrected.
Tests: test_global_scope.c (cachedb_nats) checks that the dlopen flags
carry no RTLD_GLOBAL and that none of the module's symbols resolve in
the global scope; test_json_parse.c (cachedb_nats_fts) covers decoding,
special characters, refused documents, the limits and their setters,
the 1024-level ceiling on the main stack and in a thread, concurrent
indexing, the module's own scope and the README's parameter defaults.
Fixes OpenSIPS#4501
The guard run on every JSON document cachedb_nats reads back (query rows and nats_reg_show, before cJSON) refused documents nested deeper than 64 levels or larger than 1 MiB, both fixed at compile time. Make them modparams, as in cachedb_nats_fts: json_max_depth default 64, 1..1024 (cJSON recurses once per level) json_max_bytes default 1048576, at least 2 checked when the config is read (so opensips -C reports a bad value) and again in mod_init. A json_max_bytes below max_value_size logs a warning at startup: such a usrloc row is written, then refused on every read. The parse copy is allocated with a size_t length, as data_len may now reach INT_MAX. README: both parameters, the Limitations entry, a cross-reference from max_value_size, and the difference from cachedb_nats_fts's limits of the same name. test_json_limits.c covers the defaults, the setters, the limits applied by the guard, the 1024-level ceiling, the max_value_size warning and the README sections.
NormB
force-pushed
the
fix/cachedb-nats-rtld-global
branch
from
December 4, 2026 00:57
295f66d to
3a665c2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4501.
cachedb_natsno longer asks forRTLD_GLOBAL, so none of its symbols reach the global scope.cachedb_nats_fts, which needed that flag to use the JSON scanners incachedb_nats, now parses documents with the core's cJSON (lib/cJSON.h). Withrtpengineloaded aftercachedb_nats, the "RTPEngine notification receiver" is forked again.Details
cachedb_natswas openedRTLD_NOW | RTLD_GLOBALso thatcachedb_nats_ftscould resolvecdbn_skip_ws,cdbn_parse_json_stringandcdbn_skip_json_value. The flag also putstruct module_exports exportsin the global scope. In a module loaded after it, a reference to its ownexportsbound to the one incachedb_nats.rtpengine'snotification_socksetter therefore wrotecachedb_nats'sexports.procs, and its own process was never forked.Solution
cachedb_natsusesDEFAULT_DLFLAGS.cachedb_nats_ftsparses with cJSON and uses nothing fromcachedb_nats's JSON code.cachedb_nats_ftsparameters:json_max_depth(default 64, range 1–1024)json_max_bytes(default 1048576, at least 2)cachedb_natsalready refused documents it reads back if they were nested deeper than 64 levels or larger than 1 MiB. Those limits were fixed at compile time; they are now parameters of the same names and defaults. A warning is logged at startup ifjson_max_bytesis belowmax_value_size.opensips -Creports it.Compatibility
How it was tested
make test-cachedb_nats test-cachedb_nats_ftspasses 1248/1248 and 242/242 under:-Werror)exportsin the global scope; rtpengine loaded after it never forks its notification receiver #4501 configuration:cachedb_natsreads are refused at its configured limitsFixes #4501