You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSON parsing silently replaces duplicate object members and ignores trailing text #10
A caller that has to refuse a whole document it cannot read unambiguously
has no way to do so with the JSON parser. Two behaviours hide the problem
before the caller sees the parsed tree.
JsonObjectAppendElement() calls JsonObjectRemoveKey() first
(libutils/json.c), so while parsing, a second member of the same name
replaces the first. Counterexample, parsed with JsonParse():
{"vars": {"good": null, "good": "ok"}}
returns JSON_PARSE_OK with vars.good == "ok". The null is gone
before any validation of the tree can reject it. Likewise {"vars": {"a": "1"}, "classes": {}, "vars": {"b": "2"}} loses the
whole first vars section.
JsonParse() stops at the end of the first value, and JsonParseAnyFile(), JsonParseFile() and JsonReadDataFile() call it. {"vars": {"good": "ok"}} not-json is accepted as the valid prefix. JsonParseAll() refuses trailing text but still replaces duplicates.
RFC 8259 section 4 leaves the behaviour with duplicate names unpredictable
and lists "report an error" as one implementation choice; Jansson offers it
as the opt-in flag JSON_REJECT_DUPLICATES, and requires the whole input
to be consumed unless JSON_DISABLE_EOF_CHECK is set.
Changing the default behaviour would change what every policy reading JSON
sees, so the proposal is opt-in: new JsonParseStrict() and JsonParseFileStrict() that refuse a duplicate member at any depth before
it replaces anything (new JSON_PARSE_ERROR_OBJECT_DUPLICATE_KEY) and
trailing non-whitespace (JSON_PARSE_ERROR_INVALID_END), keeping the size
cap. Every existing function stays as it is.
Found by review of frdminc/tendcf#41 (finding A2):
the CMDB loader of the pinned engine validates the parsed tree, so it cannot
see what the parser already discarded.
Activity
linear-code commentedon Nov 14, 2026
VIB-356