Skip to content

Deviation on augment node is not supported properly. #462

@corrollFang

Description

@corrollFang

Deviation is not supported properly if it targets on an augment node on libyang-0.14.75, there may be 2 blew problems.

  1. There is an error during lys_set_disabled(), error info is as below:
netopeer2-server[9357]: libyang error: Schema node not found.
netopeer2-server[9357]: libyang error: Internal error (/libyang-fbfc9c7774212c09b048418da38b0883084eb317/src/tree_schema.c:4090).

-------------Code location: -------------

static void
lys_switch_deviation(struct lys_deviation *dev, const struct lys_module *module, struct unres_schema *unres)
{
....
                    if (reapply) {
                        /* augment is supposed to be applied, so fix pointers in target and the status of the original node */
                        parent->flags |= LYS_NOTAPPLIED; /* allow apply_aug() */
                        apply_aug((struct lys_node_augment *)parent, unres);
                    }
                } else if (parent && (parent->nodetype == LYS_USES)) {
                    /* uses child */
                    lys_node_addchild(parent, NULL, dev->orig_node);
                } else {
                    /* non-augment, non-toplevel */
                    parent_path = strndup(dev->target_name, strrchr(dev->target_name, '/') - dev->target_name);
                    ret = resolve_schema_nodeid(parent_path, NULL, module, &set, 0, 1);
                    free(parent_path);
                    if (ret == -1) {//-------Returns error, because the target_node is defined in augment module, it has already been removed, so the target is not found.
                        LOGINT;
                        ly_set_free(set);
                        return;
                    }
                    target = set->set.s[0];
                    ly_set_free(set);

                    lys_node_addchild(target, NULL, dev->orig_node);
                }
...
}
  1. The process crashed because of null pointer during lys_parse_path(), the coredump stack is as below:
warning: Source file is more recent than executable, I assume the issued is caused by 1st item.
4207        lys_node_module(dev->orig_node)->deviated = 1; /* main module */
(gdb) p dev->orig_node
$1 = (struct lys_node *) 0x0
(gdb) bt
#0  0xf449d5a3 in apply_dev (unres=<optimized out>, module=0xece6f4a0, dev=0xece699f8)
    at libyang-fbfc9c7774212c09b048418da38b0883084eb317/src/tree_schema.c:4207
#1  lys_sub_module_apply_devs_augs (module=0xece6f4a0)
    at libyang-fbfc9c7774212c09b048418da38b0883084eb317/src/tree_schema.c:4264
#2  0xf443a706 in lys_set_enabled (module=module@entry=0xece6f438)
    at libyang-fbfc9c7774212c09b048418da38b0883084eb317/src/context.c:1208
#3  0xf4458501 in lyp_ctx_check_module (module=module@entry=0xece6ab68)
    at libyang-fbfc9c7774212c09b048418da38b0883084eb317/src/parser.c:3705
#4  0xf4488b7d in yyparse (scanner=0xece6f380, param=param@entry=0xf3b7d160)
    at libyang-fbfc9c7774212c09b048418da38b0883084eb317/src/parser_yang_bis.c:3708
#5  0xf44913fa in yang_parse_mem (module=module@entry=0xece6ab68, submodule=submodule@entry=0x0, unres=0xece67bc0, 
    data=data@entry=0xf3333000 "module deviation-base{\r\n\r\n    namespace \"http://deviation-base\";\r\n    prefix \"base\";\r\n    revision \"2018-03-05\"{\r\n        description\r\n", ' ' <repeats 12 times>, "\"Initial revision.\";\r\n    }\r\n\r\n    container", size_data=size_data@entry=0, node=node@entry=0xf3b7d1dc)
    at libyang-fbfc9c7774212c09b048418da38b0883084eb317/src/parser_yang.c:2528
#6  0xf4495b5b in yang_read_module (ctx=ctx@entry=0xece5c2c8, 
    data=data@entry=0xf3333000 "module deviation-base{\r\n\r\n    namespace \"http://deviation-base\";\r\n    prefix \"base\";\r\n    revision \"2018-03-05\"{\r\n        description\r\n", ' ' <repeats 12 times>, "\"Initial revision.\";\r\n    }\r\n\r\n    container", size=size@entry=0, revision=revision@entry=0x0, implement=implement@entry=1)
    at libyang-fbfc9c7774212c09b048418da38b0883084eb317/src/parser_yang.c:2607
#7  0xf449f8ff in lys_parse_mem_ (ctx=ctx@entry=0xece5c2c8, 
    data=0xf3333000 "module deviation-base{\r\n\r\n    namespace \"http://deviation-base\";\r\n    prefix \"base\";\r\n    revision \"2018-03-05\"{\r\n        description\r\n", ' ' <repeats 12 times>, "\"Initial revision.\";\r\n    }\r\n\r\n    container", format=format@entry=LYS_IN_YANG, revision=revision@entry=0x0, internal=internal@entry=1, 
    implement=implement@entry=1)
    at libyang-fbfc9c7774212c09b048418da38b0883084eb317/src/tree_schema.c:955
#8  0xf449fa85 in lys_parse_fd_ (ctx=ctx@entry=0xece5c2c8, fd=fd@entry=109, format=format@entry=LYS_IN_YANG, 
    revision=revision@entry=0x0, implement=implement@entry=1)
    at libyang-fbfc9c7774212c09b048418da38b0883084eb317/src/tree_schema.c:1115
#9  0xf449fbfe in lys_parse_fd (ctx=ctx@entry=0xece5c2c8, fd=fd@entry=109, format=format@entry=LYS_IN_YANG)
    at libyang-fbfc9c7774212c09b048418da38b0883084eb317/src/tree_schema.c:1089
#10 0xf449fc64 in lys_parse_path (ctx=0xece5c2c8, path=0x8064bc2 "deviation-base.yang", format=LYS_IN_YANG)
    at libyang-fbfc9c7774212c09b048418da38b0883084eb317/src/tree_schema.c:1046

------------------YANG models-----------------------------
-----------module deviation-base--------

module deviation-base{

    namespace "http://deviation-base";
    prefix "base";
    revision "2018-03-05"{
        description
            "Initial revision.";
    }

    container c1
    {
        leaf flag
        {
            type boolean;
            default true;
        }
    }
}

---------module deviation-augment-----------

module deviation-augment {

    namespace "http://deviation-augment";
    prefix "deviation-augment";

    import deviation-base {
        prefix "base";
    }

    revision "2018-03-05"{
        description
            "Initial revision.";
    }
    
    augment /base:c1 {
        container aug-c1 {
            leaf aug-node {
              type string;
              description
               "Test deviation on augment node.";
            }
            leaf aug-dev {
              type string;
              description
               "Marked as not-supported in deviation.";
            }
        }
    }
}

-------------module test-deviation--------------

module test-deviation {

    namespace "http://test-deviation";
    prefix "test-deviation";

    import deviation-base {
        prefix "base";
    }
    import deviation-augment {
        prefix "aug";
    }

    revision "2018-03-05"{
        description
            "Initial revision.";
    }

    deviation /base:c1/aug:aug-c1/aug:aug-dev {
        deviate not-supported;
    }
}

-----------------Test code--------------------

    //Test deviation on augment
    const struct lys_module* lModule_deviation_base = lys_parse_path(lLyCtxt_tmp, "deviation-base.yang", LYS_IN_YANG);
    const struct lys_module* lModule_dev_augment = lys_parse_path(lLyCtxt_tmp, "deviation-augment.yang", LYS_IN_YANG);
    const struct lys_module* lModule_deviation = lys_parse_path(lLyCtxt_tmp, "test-deviation.yang", LYS_IN_YANG);

    //There are similar code in "dm_release_tmp_ly_ctx()" in sysrepo
    uint32 lIndex = ly_ctx_internal_modules_count(lLyCtxt_tmp);
    const struct lys_module* lModule = ly_ctx_get_module_iter(lLyCtxt_tmp, &lIndex);
    while(lModule)
    {
        int lResult = lys_set_disabled(lModule); //print error for "test-deviation.yang"
        lModule = ly_ctx_get_module_iter(lLyCtxt_tmp, &lIndex);
    }

    //It may be triggered by sr_get_schema()
    lModule_deviation_base = lys_parse_path(lLyCtxt_tmp, "deviation-base.yang", LYS_IN_YANG);//Crashed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions