json BUGFIX opaq node cannot have an empty name
diff --git a/src/parser_json.c b/src/parser_json.c
index f3442d4..befe9a3 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1217,6 +1217,13 @@
/* parse as an opaq node */
assert((lydctx->parse_opts & LYD_PARSE_OPAQ) || (lydctx->int_opts));
+ /* opaq node cannot have an empty string as the name. */
+ if (name_len == 0) {
+ LOGVAL(lydctx->jsonctx->ctx, LYVE_SYNTAX_JSON, "A JSON object member name cannot be a zero-length string.");
+ ret = LY_EVALID;
+ goto cleanup;
+ }
+
/* move to the second item in the name/X pair */
ret = lyjson_ctx_next(lydctx->jsonctx, &status);
LY_CHECK_GOTO(ret, cleanup);
diff --git a/tests/utests/data/test_parser_json.c b/tests/utests/data/test_parser_json.c
index 6b1ad83..51d6ef7 100644
--- a/tests/utests/data/test_parser_json.c
+++ b/tests/utests/data/test_parser_json.c
@@ -414,6 +414,10 @@
CHECK_LYD_NODE_OPAQ((struct lyd_node_opaq *)tree, 0, 0x1, LY_VALUE_JSON, "l1", 0, 0, NULL, 0, "");
CHECK_LYD_STRING(tree, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS, data);
lyd_free_all(tree);
+
+ /* empty name */
+ PARSER_CHECK_ERROR("{\"@a:foo\":{\"\":0}}", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID,
+ "A JSON object member name cannot be a zero-length string.", "Line number 1.");
}
static void