Skip to content

Commit 4001573

Browse files
committed
parser BUGFIX skip new validation on multi-error
Because it could cause auto-deletion, which in turn invalid memory access.
1 parent 3fc15ea commit 4001573

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

src/parser_json.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,8 +1434,8 @@ lydjson_parse_instance_inner(struct lyd_json_ctx *lydctx, const struct lysc_node
14341434
LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup);
14351435
}
14361436

1437-
if (!(lydctx->parse_opts & LYD_PARSE_ONLY)) {
1438-
/* new node validation, autodelete CANNOT occur, all nodes are new */
1437+
if (!(lydctx->parse_opts & LYD_PARSE_ONLY) && !rc) {
1438+
/* new node validation, autodelete CANNOT occur (it can if multi-error), all nodes are new */
14391439
r = lyd_validate_new(lyd_node_child_p(*node), snode, NULL, lydctx->val_opts, NULL);
14401440
LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup);
14411441

src/parser_xml.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,8 @@ lydxml_subtree_inner(struct lyd_xml_ctx *lydctx, const struct lysc_node *snode,
845845
LY_CHECK_ERR_GOTO(r, rc = r, cleanup);
846846
}
847847

848-
if (!(lydctx->parse_opts & LYD_PARSE_ONLY)) {
849-
/* new node validation, autodelete CANNOT occur, all nodes are new */
848+
if (!(lydctx->parse_opts & LYD_PARSE_ONLY) && !rc) {
849+
/* new node validation, autodelete CANNOT occur (it can if multi-error), all nodes are new */
850850
r = lyd_validate_new(lyd_node_child_p(*node), snode, NULL, lydctx->val_opts, NULL);
851851
LY_DPARSER_ERR_GOTO(r, rc = r, lydctx, cleanup);
852852

tests/utests/data/test_validation.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,8 +1202,6 @@ test_multi_error(void **state)
12021202
CHECK_LOG_CTX_APPTAG("Too few \"ll\" instances.", "Schema location \"/ii:cont/ll\".", "too-few-elements");
12031203
CHECK_LOG_CTX_APPTAG("l leaf is not left", "Data location \"/ii:cont/l3\".", "not-left");
12041204
CHECK_LOG_CTX_APPTAG("Must condition \"../l = 'right'\" not satisfied.", "Data location \"/ii:cont/l2\".", "must-violation");
1205-
CHECK_LOG_CTX_APPTAG("Duplicate instance of \"l\".", "Data location \"/ii:cont/l\", line number 7.", NULL);
1206-
CHECK_LOG_CTX_APPTAG("Duplicate instance of \"l\".", "Data location \"/ii:cont/l\", line number 7.", NULL);
12071205
CHECK_LOG_CTX_APPTAG("Invalid type uint32 value \"ahoy\".", "Data location \"/ii:cont/ll\", line number 6.", NULL);
12081206

12091207
/* json */
@@ -1220,8 +1218,6 @@ test_multi_error(void **state)
12201218
CHECK_LOG_CTX_APPTAG("Too few \"ll\" instances.", "Schema location \"/ii:cont/ll\".", "too-few-elements");
12211219
CHECK_LOG_CTX_APPTAG("l leaf is not left", "Data location \"/ii:cont/l3\".", "not-left");
12221220
CHECK_LOG_CTX_APPTAG("Must condition \"../l = 'right'\" not satisfied.", "Data location \"/ii:cont/l2\".", "must-violation");
1223-
CHECK_LOG_CTX_APPTAG("Duplicate instance of \"l\".", "Data location \"/ii:cont/l\", line number 9.", NULL);
1224-
CHECK_LOG_CTX_APPTAG("Duplicate instance of \"l\".", "Data location \"/ii:cont/l\", line number 9.", NULL);
12251221
CHECK_LOG_CTX_APPTAG("Invalid non-number-encoded uint32 value \"ahoy\".", "Data location \"/ii:cont/ll\", line number 7.", NULL);
12261222

12271223
/* validation */

0 commit comments

Comments
 (0)