schema BUGFIX accessing extension plugins
The plugin in extension is not mandatory, so be more careful when
accessing plugin's callbacks and check that the plugin is actually
present.
Fixes #1492
diff --git a/src/printer_yang.c b/src/printer_yang.c
index 95ba4f3..5833a15 100644
--- a/src/printer_yang.c
+++ b/src/printer_yang.c
@@ -2347,7 +2347,7 @@
LEVEL++;
yprc_extension_instances(ctx, LY_STMT_EXTENSION_INSTANCE, 0, ext[u].exts, &inner_flag, 0);
- if (ext[u].def->plugin->sprinter) {
+ if (ext[u].def->plugin && ext[u].def->plugin->sprinter) {
ext[u].def->plugin->sprinter(&ctx->printer_ctx, &ext[u], &inner_flag);
}
diff --git a/src/validation.c b/src/validation.c
index 86d47d8..b97a415 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -257,7 +257,7 @@
struct node_ext *rec;
LY_ARRAY_FOR(exts, const struct lysc_ext_instance, ext) {
- if (ext->def->plugin->validate) {
+ if (ext->def->plugin && ext->def->plugin->validate) {
rec = malloc(sizeof *rec);
LY_CHECK_ERR_RET(!rec, LOGMEM(LYD_CTX(node)), LY_EMEM);
rec->ext = ext;
diff --git a/tests/utests/basic/test_plugins.c b/tests/utests/basic/test_plugins.c
index 81a991d..ebb835c 100644
--- a/tests/utests/basic/test_plugins.c
+++ b/tests/utests/basic/test_plugins.c
@@ -138,6 +138,35 @@
lyd_free_all(tree);
}
+static void
+test_not_implemented(void **state)
+{
+ const struct lys_module *mod;
+ struct lyd_node *tree;
+ const char *schema = "module libyang-plugins-unknown {"
+ " namespace urn:libyang:tests:plugins:unknown;"
+ " prefix u;"
+ " extension myext;"
+ " typedef mytype { type string;}"
+ " leaf test {"
+ " u:myext;"
+ " type mytype;"
+ " }"
+ "}";
+ const char *data = "<test xmlns=\"urn:libyang:tests:plugins:unknown\">xxx</test>";
+ char *printed = NULL;
+
+ UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, &mod);
+
+ assert_int_equal(LY_SUCCESS, lys_print_mem(&printed, mod, LYS_OUT_YANG_COMPILED, 0));
+ free(printed);
+
+ assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree));
+ CHECK_LOG_CTX(NULL, NULL);
+
+ lyd_free_all(tree);
+}
+
int
main(void)
{
@@ -145,6 +174,7 @@
UTEST(test_add_invalid),
UTEST(test_add_simple),
UTEST(test_validation),
+ UTEST(test_not_implemented),
};
return cmocka_run_group_tests(tests, NULL, NULL);