diff --git a/src/parser_internal.h b/src/parser_internal.h
index 90b36c450..d315223c0 100644
--- a/src/parser_internal.h
+++ b/src/parser_internal.h
@@ -42,7 +42,7 @@ struct lysp_ctx;
err_cmd; \
const struct ly_err_item *__eitem = ly_err_last(((struct lyd_ctx *)lydctx)->data_ctx->ctx); \
if ((r != LY_EVALID) || !lydctx || !(lydctx->val_opts & LYD_VALIDATE_MULTI_ERROR) || \
- (__eitem->vecode == LYVE_SYNTAX)) { \
+ !__eitem || (__eitem->vecode == LYVE_SYNTAX)) { \
goto label; \
} \
}
diff --git a/src/plugins_types/xpath1.0.c b/src/plugins_types/xpath1.0.c
index f82fe8f35..3932ad593 100644
--- a/src/plugins_types/xpath1.0.c
+++ b/src/plugins_types/xpath1.0.c
@@ -484,7 +484,11 @@ lyplg_type_validate_tree_xpath10(const struct ly_ctx *UNUSED(ctx), const struct
ly_err_new_no_mem(err);
} else if (ret) {
eitem = ly_err_last(LYD_CTX(ctx_node));
- ly_err_new(err, ret, LYVE_DATA, eitem->data_path, NULL, "%s", eitem->msg);
+ if (eitem) {
+ ly_err_new(err, ret, LYVE_DATA, eitem->data_path, NULL, "%s", eitem->msg);
+ } else {
+ ly_err_new(err, ret, LYVE_DATA, NULL, NULL, "Failed to get the schema-mount prefix mappings.");
+ }
}
return ret;
}
diff --git a/src/tree_data.c b/src/tree_data.c
index 51421e678..b51620127 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -159,9 +159,8 @@ lyd_parse(const struct ly_ctx *ctx, struct lyd_node *parent, struct lyd_node **f
}
eitem = ly_err_last(ctx);
- assert(eitem);
- if (eitem->vecode == LYVE_SYNTAX) {
- /* cannot get more errors on a syntax error */
+ if (!eitem || (eitem->vecode == LYVE_SYNTAX)) {
+ /* cannot get more errors on a syntax error or without the stored error */
goto cleanup;
}
}
diff --git a/tests/utests/data/test_parser_xml.c b/tests/utests/data/test_parser_xml.c
index 3c169e5b5..a5ef90f31 100644
--- a/tests/utests/data/test_parser_xml.c
+++ b/tests/utests/data/test_parser_xml.c
@@ -74,6 +74,7 @@ test_leaf(void **state)
const char *data = "foo value";
struct lyd_node *tree;
struct lyd_node_term *leaf;
+ uint32_t prev_lo;
assert_non_null(ly_ctx_load_module(UTEST_LYCTX, "ietf-netconf-with-defaults", "2011-06-01", NULL));
@@ -118,6 +119,14 @@ test_leaf(void **state)
data = "val-aval-b10";
PARSER_CHECK_ERROR(data, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
"Invalid boolean value \"0\".", "/a:l1[a='val-a'][b='val-b'][c='1']/cont/e", 1);
+
+ /* invalid value with multiple errors allowed while the errors are not stored */
+ data = "x";
+ prev_lo = ly_log_options(LY_LOLOG);
+ assert_int_equal(LY_EVALID, lyd_parse_data_mem(UTEST_LYCTX, data, LYD_XML, 0,
+ LYD_VALIDATE_PRESENT | LYD_VALIDATE_MULTI_ERROR, &tree));
+ ly_log_options(prev_lo);
+ assert_null(tree);
}
static void