Skip to content

Commit fa87cc5

Browse files
committed
context UPDATE fail on invalid yang-library data
Also, require the pointer to point to the yang-library data. Allows using mounted data.
1 parent c1f705f commit fa87cc5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/context.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,12 @@ ly_ctx_new_yl_legacy(struct ly_ctx *ctx, const struct lyd_node *yltree)
370370
LY_ERR ret = LY_SUCCESS;
371371
uint32_t i, j;
372372

373-
LY_CHECK_RET(ret = lyd_find_xpath(yltree, "/ietf-yang-library:yang-library/modules-state/module", &set));
373+
LY_CHECK_RET(ret = lyd_find_xpath(yltree, "modules-state/module", &set));
374+
375+
if (!set->count) {
376+
ret = LY_ENOTFOUND;
377+
goto cleanup;
378+
}
374379

375380
/* process the data tree */
376381
for (i = 0; i < set->count; ++i) {
@@ -489,7 +494,7 @@ ly_ctx_new_yldata(const char *search_dir, const struct lyd_node *tree, int optio
489494
ly_bool no_expl_compile = 0;
490495
uint32_t i, j;
491496

492-
LY_CHECK_ARG_RET(NULL, tree, ctx, LY_EINVAL);
497+
LY_CHECK_ARG_RET(NULL, tree, !strcmp(LYD_NAME(tree), "yang-library"), ctx, LY_EINVAL);
493498

494499
/* create a new context */
495500
if (*ctx == NULL) {
@@ -504,7 +509,7 @@ ly_ctx_new_yldata(const char *search_dir, const struct lyd_node *tree, int optio
504509
no_expl_compile = 1;
505510
}
506511

507-
LY_CHECK_GOTO(ret = lyd_find_xpath(tree, "/ietf-yang-library:yang-library/module-set[1]/module", &set), cleanup);
512+
LY_CHECK_GOTO(ret = lyd_find_xpath(tree, "module-set[1]/module", &set), cleanup);
508513
if (set->count == 0) {
509514
/* perhaps a legacy data tree? */
510515
LY_CHECK_GOTO(ret = ly_ctx_new_yl_legacy(ctx_new, tree), cleanup);

src/context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ LIBYANG_API_DECL LY_ERR ly_ctx_new_ylmem(const char *search_dir, const char *dat
316316
*
317317
* @param[in] search_dir Directory where libyang will search for the imported or included modules and submodules.
318318
* If no such directory is available, NULL is accepted.
319-
* @param[in] tree Data tree containing yang-library data.
319+
* @param[in] tree Data tree pointing to the 'yang-library' data.
320320
* @param[in] options Context options, see @ref contextoptions.
321321
* @param[in,out] ctx If *ctx is not NULL, the existing libyang context is modified. Otherwise, a pointer to a
322322
* newly created context is returned here if LY_SUCCESS.

0 commit comments

Comments
 (0)