Skip to content

plugins exts BUGFIX find parsed ext instance in submodules - #2578

Open
iliasabk wants to merge 1 commit into
CESNET:masterfrom
iliasabk:fix/submodule-ext-parsed-lookup
Open

iliasabk wants to merge 1 commit into
CESNET:masterfrom
iliasabk:fix/submodule-ext-parsed-lookup

Conversation

@iliasabk

Copy link
Copy Markdown

Closes: #2575

lyplg_ext_parsed_get_storage() searches only ext->module->parsed->exts for the parsed extension instance. However, top-level extension instances of a submodule are compiled into the main module's compiled extension array (mod_c->exts), while their parsed counterparts remain in the submodule's lysp_submodule::exts. For such instances the lookup fails and the unconditional assert(extp) aborts the process.

Reproducer

module tops {
  yang-version 1.1;
  namespace "urn:tops";
  prefix tp;
  include subs;
  import ietf-yang-structure-ext { prefix sx; }
  sx:structure basetop {
    container c { leaf x { type string; } }
  }
}
submodule subs {
  yang-version 1.1;
  belongs-to tops { prefix tp; }
  import ietf-yang-structure-ext { prefix sx; }
  sx:augment-structure "/tops:basetop/tops:c" {
    leaf y { type string; }
  }
}
$ yanglint -f tree -p . tops.yang
Assertion failed: (extp), function lyplg_ext_parsed_get_storage, file plugins_exts.c, line 580.
Abort trap: 6

The same lookup is reached during compilation when children of a submodule extension instance resolve typedefs or groupings (e.g. an sx:structure with an internal typedef placed in a submodule), so the crash is not limited to printing.

Fix

Search the parsed extension arrays of all included submodules as a fallback when the instance is not found in the main module's parsed extension array. The lookup semantics (first match by extension name) are unchanged.

Regression test

test_submod in tests/utests/extensions/test_structure.c parses a module whose submodule contains a top-level sx:augment-structure and prints its tree with LY_CTX_SET_PRIV_PARSED (which is what yanglint -f tree sets). Before the fix this asserts; with the fix the augment-structure section is printed correctly.

lyplg_ext_parsed_get_storage() searches only the parsed extension
instances of the module itself. However, top-level extension
instances of a submodule are compiled into the main module's
compiled extension array, so their parsed counterparts live in the
submodule's parsed extension array and the lookup failed, hitting
the assert.

This could be triggered, for example, by a submodule top-level
sx:augment-structure instance when printing the module tree with
compiled nodes (LY_CTX_SET_PRIV_PARSED) or when resolving typedefs
of extension instance children during compilation.

Search the parsed extension arrays of all included submodules as a
fallback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion when printing trees

1 participant