Skip to content

Commit b7b29e6

Browse files
lePicimichalvasko
authored andcommitted
json BUGFIX opaq node cannot have an empty name
1 parent 023f83a commit b7b29e6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/parser_json.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,13 @@ lydjson_subtree_r(struct lyd_json_ctx *lydctx, struct lyd_node *parent, struct l
12171217
/* parse as an opaq node */
12181218
assert((lydctx->parse_opts & LYD_PARSE_OPAQ) || (lydctx->int_opts));
12191219

1220+
/* opaq node cannot have an empty string as the name. */
1221+
if (name_len == 0) {
1222+
LOGVAL(lydctx->jsonctx->ctx, LYVE_SYNTAX_JSON, "A JSON object member name cannot be a zero-length string.");
1223+
ret = LY_EVALID;
1224+
goto cleanup;
1225+
}
1226+
12201227
/* move to the second item in the name/X pair */
12211228
ret = lyjson_ctx_next(lydctx->jsonctx, &status);
12221229
LY_CHECK_GOTO(ret, cleanup);

tests/utests/data/test_parser_json.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ test_opaq(void **state)
414414
CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_VALUE_JSON, "l1", 0, 0, NULL, 0, "");
415415
CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
416416
lyd_free_all(tree);
417+
418+
/* empty name */
419+
PARSER_CHECK_ERROR("{\"@a:foo\":{\"\":0}}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
420+
"A JSON object member name cannot be a zero-length string.", "Line number 1.");
417421
}
418422

419423
static void

0 commit comments

Comments
 (0)