CESNET / libyang

YANG data modeling language library
BSD 3-Clause "New" or "Revised" License
364 stars 291 forks source link

SIGSEGV in lyd_validate for RPC intput data tree #122

Closed milanlenco closed 8 years ago

milanlenco commented 8 years ago

YANG schema:

rpc activate-software-image {
  input {
    leaf image-name {
      type string;
    }
    leaf location {
      type string;
      default "/";
    }
  }
  output {
    leaf status {
      type string;
    }
  }
}

data tree:

<activate-software-image>
  <input>
    <image-name>acmefw-2.3</image-name>
  </input>
</activate-software-image>

lyd_validate causes an invalid memory access:

#1  <signal handler called>
#2  in lyd_validate (node=0x7fffffffd7b8, options=272) at libyang/src/tree_data.c:3475
#3  in sr_node_t_rpc_input_test (state=0x64e1d0) at tests/common_test.c:794
#4  in cmocka_run_one_test_or_fixture (function_name=0x42ffa1 "sr_node_t_rpc_input_test", test_func=0x40fe23 <sr_node_t_rpc_input_test>, setup_func=0x0, teardown_func=0x0, state=0x64e1d0, heap_check_point=0x0) at cmocka/src/cmocka.c:2534
#5  in cmocka_run_one_tests (test_state=0x64e1c0) at cmocka/src/cmocka.c:2642
#6  in _cmocka_run_group_tests (group_name=0x42fee9 "tests", tests=0x7fffffffd970, num_tests=12, group_setup=0x0, group_teardown=0x0) at cmocka/src/cmocka.c:2757
#7  in main () at tests/common_test.c:1035
(gdb) frame 2
#2  in lyd_validate (node=0x7fffffffd7b8, options=272) at libyang/src/tree_data.c:3475
(gdb) list
3470                        goto cleanup;
3471                    }
3472                }
3473
3474                /* move it to the beginning */
3475                for (; data_tree->prev->next; data_tree = data_tree->prev);
3476
3477                /* LYD_OPT_NOSIBLINGS cannot be set in this case */
3478                if (options & LYD_OPT_NOSIBLINGS) {
3479                    LOGERR(LY_EINVAL, "%s: invalid parameter (variable arg const struct lyd_node *data_tree with LYD_OPT_NOSIBLINGS).", __func__);
milanlenco commented 8 years ago

This is for the latest devel version of libyang (0.10.130).

michalvasko commented 8 years ago

Hi Milan, this is almost positively the result of a forgotten lyd_validate() parameter, it was expected in more cases in 0.10.130. Nevertheless, in the current version it was changed from a variable to argument to a standard one, so no one should forget it now (you can still set it to NULL).

Regards, Michal

milanlenco commented 8 years ago

Hi Michal,

yes, the missing argument was the issue. I put there NULL for now, it is sufficient for out current unit test set to pass. But this YANG 1.1 extension makes the cross-module dependencies task even more complicated and nobody is really keen to start working on it now :)

Thanks, Milan