Skip to content

Commit 1049c19

Browse files
stewegmichalvasko
authored andcommitted
validation BUGFIX segfault when using containter with when condition
This patch fixes the segfault, which is happening when RPC output data, which uses NP-container with when condition are being validated.
1 parent 462d7ea commit 1049c19

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/validation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,7 @@ lyd_validate_tree(struct lyd_node *root, const struct lysc_ext_instance *ext, st
19691969

19701970
if (lysc_has_when(node->schema)) {
19711971
/* when evaluation */
1972-
r = ly_set_add(node_when, (void *)node, 1, NULL);
1972+
r = ly_set_add(node_when, (void *)node, 0, NULL);
19731973
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
19741974
}
19751975

tests/utests/data/test_validation.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,43 @@ test_when(void **state)
7272
lyd_free_all(tree);
7373
}
7474

75+
static void
76+
test_when_rpc_reply(void **state)
77+
{
78+
struct ly_in *in;
79+
struct lyd_node *tree;
80+
const char *schema =
81+
"module a {\n"
82+
" namespace urn:tests:a;\n"
83+
" prefix a;\n"
84+
" yang-version 1.1;\n"
85+
"\n"
86+
" rpc rpc1 {\n"
87+
" output {\n"
88+
" container c1 {\n"
89+
" when \"../c = 'val_c'\";\n"
90+
" leaf a {\n"
91+
" type string;\n"
92+
" }\n"
93+
" }\n"
94+
" leaf c {\n"
95+
" type string;\n"
96+
" }\n"
97+
" }\n"
98+
" }\n"
99+
"}";
100+
101+
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
102+
103+
const char *data = "{\"a:rpc1\": {\"c\":\"wrong\"}}";
104+
105+
assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
106+
assert_int_equal(LY_SUCCESS, lyd_parse_op(UTEST_LYCTX, NULL, in, LYD_JSON, LYD_TYPE_REPLY_YANG, 0, NULL, &tree));
107+
assert_int_equal(LY_SUCCESS, lyd_validate_op(tree, NULL, LYD_TYPE_REPLY_YANG, NULL));
108+
ly_in_free(in, 0);
109+
lyd_free_all(tree);
110+
}
111+
75112
static void
76113
test_mandatory_when(void **state)
77114
{
@@ -1600,6 +1637,7 @@ main(void)
16001637
{
16011638
const struct CMUnitTest tests[] = {
16021639
UTEST(test_when),
1640+
UTEST(test_when_rpc_reply),
16031641
UTEST(test_mandatory),
16041642
UTEST(test_mandatory_when),
16051643
UTEST(test_type_incomplete_when),

0 commit comments

Comments
 (0)