Skip to content

Commit 829499c

Browse files
committed
added constrains for extension parsing
1 parent b456cf6 commit 829499c

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

tools/lint/cmd_data.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,6 @@ parse_extension_instance(struct ly_ctx *ctx, struct yl_opt *yo, struct cmdline_f
651651
{
652652

653653
LY_ERR ret = LY_SUCCESS;
654-
struct lyd_node *tree_copy;
655654

656655
if (find_extension(ctx, yo)) {
657656
YLMSG_E("Extension '%s:%s:%s' not found in module.", yo->mod_name, yo->name, yo->argument);
@@ -663,16 +662,23 @@ parse_extension_instance(struct ly_ctx *ctx, struct yl_opt *yo, struct cmdline_f
663662
return ret;
664663
}
665664

666-
lyd_dup_siblings(*tree, NULL, LYD_DUP_RECURSIVE, &tree_copy);
667-
668-
if (oper_tree) {
669-
lyd_insert_sibling(tree_copy, oper_tree, &tree_copy);
665+
if (!(*tree)) {
666+
YLMSG_E("Nothing to validate in the extension input data.");
667+
return LY_EDENIED;
670668
}
671669

672-
ret = lyd_validate_all(&tree_copy, ctx, yo->data_validate_options, NULL);
670+
if ((*tree)->next) {
671+
YLMSG_E("Yanglint does not support more than one top-level node in extension data.");
672+
return LY_EDENIED;
673+
}
673674

674-
if (!yo->data_operational.in) {
675-
lyd_free_all(tree_copy);
675+
/* Operational data is present */
676+
if (oper_tree) {
677+
lyd_insert_sibling(*tree, oper_tree, &oper_tree);
678+
ret = lyd_validate_all(tree, ctx, yo->data_validate_options, NULL);
679+
lyd_unlink_tree(*tree);
680+
} else {
681+
ret = lyd_validate_all(tree, ctx, yo->data_validate_options, NULL);
676682
}
677683

678684
yo->data_ext = 0;

0 commit comments

Comments
 (0)