From 425e0e92a3b9515041d5df37df7a96b2816ed388 Mon Sep 17 00:00:00 2001 From: Mohil-Ahuja Date: Fri, 4 Dec 2026 11:24:37 +0530 Subject: [PATCH] xml BUGFIX unexpected end of input after '<' A '<' followed by the terminating zero of an input without a length was treated as the end of the document even with elements still open, so a truncated document such as '<' was accepted. Report the unexpected end of input instead. --- src/xml.c | 6 +++++- tests/utests/data/test_parser_xml.c | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/xml.c b/src/xml.c index c686b5765..d8f10da45 100644 --- a/src/xml.c +++ b/src/xml.c @@ -450,7 +450,11 @@ lyxml_skip_until_end_or_after_otag(struct lyxml_ctx *xmlctx) ++xmlctx->in->current; LY_CHECK_RET(lyxml_check_read(xmlctx, 1)); - if (xmlctx->in->current[0] == '!') { + if (xmlctx->in->current[0] == '\0') { + /* EOF right after '<' */ + LOGVAL(ctx, NULL, LY_VCODE_EOF); + return LY_EVALID; + } else if (xmlctx->in->current[0] == '!') { ++xmlctx->in->current; /* sections to ignore */ diff --git a/tests/utests/data/test_parser_xml.c b/tests/utests/data/test_parser_xml.c index 3c169e5b5..7c8a0a9db 100644 --- a/tests/utests/data/test_parser_xml.c +++ b/tests/utests/data/test_parser_xml.c @@ -363,6 +363,10 @@ test_container(void **state) cont = (struct lyd_node_inner *)tree; assert_false(cont->flags & LYD_DEFAULT); lyd_free_all(tree); + + /* input ending right after the '<' of the next tag */ + PARSER_CHECK_ERROR("<", 0, LYD_VALIDATE_PRESENT, tree, LY_EVALID, + "Unexpected end-of-input.", NULL, 1); } static void