Repository navigation
Conversation
Extension instances store a pointer to their parent statement, which may be an item of a sized array, a member of such an item (flags, an embedded type or default) or an item of a separate string array. Adding an item to such an array may move it, so the parents went stale in the YIN parser, which never updated them. The YANG parser reset the parents of statement array items to the item itself, losing the member offsets, and left the parents into separate arrays stale. Add one helper moving every parent pointing into the previous array memory to the same offset in the new one and use it wherever an array with extension instance parents grows.
fraction-digits, require-instance, value and position stored their parent's extension instance array for resolving while the parent could still add more extension instances to it. Those arrays are stored once the parent statement is parsed, the same as in the YANG parser.
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.
Every
struct lysp_ext_instancekeeps aparentpointer to the statement it belongs to. That statement is often an item of a sized array (a typedef, enum, must, revision, import, ...), a member of such an item (&enum->flagsforstatus,&tpdf->dfltfordefault), or the base of a separate array withparent_stmt_index(iffeatures,bases). WhenLYA_ADD_ITEM()grows the array andrealloc()moves it, every such parent points into the freed memory.parser_yin.cnever updated these parents after adding an item, so they went stale whenever the array moved, and were later read through them (e.g. bylysp_ext_instance_path()).parser_yang.cupdated statement array items with a loop after each add, but reset every parent to the item itself, losing the member offsets of substatement parents (status,default, ...); parents into separate arrays such asiffeatureswere not updated at all.lysp_inject_submodule()grows the main module'sincludeswithout updating them either.The fix adds one helper,
lysp_ext_parents_move()(andLYSP_ARRAY_EXT_PARENTS_MOVE()for a whole array), which moves every parent that pointed into the previous array memory to the same offset in the new memory and leaves all others untouched. It is used at every place an array with extension instance parents grows, in both parsers and inlysp_inject_submodule(), replacing the per-site loops inparser_yang.c. With one helper, a new array of statements gets correct parents by calling it rather than by repeating a hand-written loop.The second commit fixes another reference into a growing array in the YIN parser.
yin_parse_fracdigits(),yin_pasrse_reqinstance()andyin_parse_value_pos()stored their parent's extension instance array (type->exts,enm->exts) inctx->ext_instwhile the parenttype,enumorbitcould still add more extension instances to it. A later extension instance of the parent could move the array, andlysp_resolve_ext_instance_records()then read the freed memory. The parent statements already store their array once they are parsed, as in the YANG parser, so these three calls are removed; every remaining call stores the array of the statement that was just parsed.Tests:
test_ext_parent_array_reallocintests/utests/schema/test_schema.cparses the same module in YANG and YIN with three typedefs (withdefault), enums (withstatus), musts and if-features, each with extension instances, and checks every parent points to its own statement, member or array.tests/utests/basic/test_plugins.cloads the extension plugin test module in YIN too and adds musts to it; the parse callback now checks that the instance is the one stored in its parent, for enums, union types, musts, typedefs and refines in both formats.test_yin_parse_type_substmt_extsintests/utests/schema/test_yin.cparsesfraction-digits,require-instance,valueandpositionwith an extension instance, each followed by more extension instances of its parent, and checks all of them are kept in order.The full test suite passes (ASan/UBSan build).