Skip to content

Commit 3991212

Browse files
Marmichalvasko
authored andcommitted
path BUGFIX dup predicates with own type
ly_path_dup_predicates() copied the type of the first predicate into every duplicated predicate while copying the value according to the predicate's own type. With list keys given as a mix of values and variables, the duplicate predicates were printed and freed as the wrong kind.
1 parent f7e0cc1 commit 3991212

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎src/path.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ ly_path_dup_predicates(const struct ly_ctx *ctx, const struct ly_path_predicate
931931
LYA_PREALLOC(*dup, LYA_COUNT(pred), LOGMEM(ctx); return LY_EMEM);
932932
LYA_FOR(pred, u) {
933933
LYA_INCREMENT(*dup);
934-
(*dup)[u].type = pred->type;
934+
(*dup)[u].type = pred[u].type;
935935

936936
switch (pred[u].type) {
937937
case LY_PATH_PREDTYPE_POSITION:

‎tests/utests/types/instanceid.c‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,37 @@ test_plugin_lyb(void **state)
281281
TEST_SUCCESS_LYB2("lyb2", "nii", "ll[. = 'some_string']");
282282
}
283283

284+
static void
285+
test_plugin_dup(void **state)
286+
{
287+
const char *schema, *data;
288+
struct lyd_node *tree, *dup;
289+
290+
/* ietf-netconf-acm node-instance-identifier type with mixed key predicates */
291+
assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(UTEST_LYCTX, TESTS_DIR_MODULES_YANG));
292+
schema = MODULE_CREATE_YANG("dup",
293+
"import ietf-netconf-acm {prefix acm;}"
294+
"list lst {key \"k1 k2\"; leaf k1 {type string;} leaf k2 {type string;}}"
295+
"leaf-list nii {type acm:node-instance-identifier;}");
296+
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
297+
298+
data = "<nii xmlns=\"urn:tests:dup\" xmlns:aa=\"urn:tests:dup\">/aa:lst[aa:k1='a'][aa:k2=$x]</nii>"
299+
"<nii xmlns=\"urn:tests:dup\" xmlns:aa=\"urn:tests:dup\">/aa:lst[aa:k1=$x][aa:k2='a']</nii>";
300+
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, LY_SUCCESS, tree);
301+
302+
assert_int_equal(LY_SUCCESS, lyd_dup_siblings(tree, NULL, 0, &dup));
303+
CHECK_LYD(tree, dup);
304+
lyd_free_all(dup);
305+
lyd_free_all(tree);
306+
}
307+
284308
int
285309
main(void)
286310
{
287311
const struct CMUnitTest tests[] = {
288312
UTEST(test_data_xml),
289313
UTEST(test_plugin_lyb),
314+
UTEST(test_plugin_dup),
290315
};
291316

292317
return cmocka_run_group_tests(tests, NULL, NULL);

0 commit comments

Comments
 (0)