From 0a6d0ee329689d61e472787ab3f69c56037983b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Fri, 27 Nov 2026 01:13:41 +0100 Subject: [PATCH 1/3] xml/json BUGFIX copy value characters from the input Once a value needed a dynamic buffer, e.g. because of an entity reference or an escape sequence, every following character was appended by copying bytes from the address of its decoded code point. The code point, however, holds the Unicode integer value, not raw bytes in the UTF-8 encoding. This happened to work (for ASCII) on LE systems. On BE, the first byte of that integer is always zero, so the value got cut off at the next character. Any characters > 0x7f were mangled. Copy the bytes from the input instead. The tests need a non-ASCII character after the reference or the escape. Co-Authored-By: Claude Sonnet 5.5 --- src/json.c | 2 +- src/xml.c | 2 +- tests/utests/basic/test_json.c | 8 ++++++++ tests/utests/basic/test_xml.c | 11 +++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/json.c b/src/json.c index 3009ad7cc..b075a8541 100644 --- a/src/json.c +++ b/src/json.c @@ -401,7 +401,7 @@ lyjson_string(struct lyjson_ctx *jsonctx) if (buf) { LY_CHECK_GOTO(lyjson_string_use_buf(jsonctx, start, u, &buf, &len, &size), error); - memcpy(buf + len, &value, u); + memcpy(buf + len, jsonctx->in->current - u, u); len += u; } else if (jsonctx->in->current - start > UINT32_MAX) { LOGVAL(ctx, NULL, LYVE_SYNTAX, "JSON string too long."); diff --git a/src/xml.c b/src/xml.c index 40bf17db1..732c46757 100644 --- a/src/xml.c +++ b/src/xml.c @@ -765,7 +765,7 @@ lyxml_parse_value(struct lyxml_ctx *xmlctx, char endchar, char **value, uint32_t if (buf) { LY_CHECK_GOTO(lyxml_parse_value_use_buf(xmlctx, start, parsed, &buf, &len, &size), error); - memcpy(buf + len, &c, parsed); + memcpy(buf + len, xmlctx->in->current - parsed, parsed); len += parsed; } else if (xmlctx->in->current - start > UINT32_MAX) { LOGVAL(xmlctx->ctx, NULL, LYVE_SYNTAX, "XML value too long."); diff --git a/tests/utests/basic/test_json.c b/tests/utests/basic/test_json.c index fc524bd1a..92c7abfbf 100644 --- a/tests/utests/basic/test_json.c +++ b/tests/utests/basic/test_json.c @@ -514,6 +514,14 @@ test_string(void **state) lyd_free_all(tree); tree = NULL; + /* characters following an escape must be copied from the input, not from their decoded code point */ + str = "\"\\u003c€𠜎Øn\\n|\""; + assert_non_null(ly_in_memory(in, str)); + assert_int_equal(LY_SUCCESS, lyd_parse_value_fragment(ctx, "/test:l", in, LYD_JSON, 0, 0, 0, &tree)); + assert_string_equal("<€𠜎Øn\n|", lyd_get_value(tree)); + lyd_free_all(tree); + tree = NULL; + /* non-hexadecimal digits in an escaped character */ str = "\"\\u002s\""; assert_non_null(ly_in_memory(in, str)); diff --git a/tests/utests/basic/test_xml.c b/tests/utests/basic/test_xml.c index 707f5c49d..1a6bfd2d0 100644 --- a/tests/utests/basic/test_xml.c +++ b/tests/utests/basic/test_xml.c @@ -190,6 +190,9 @@ test_text(void **state) " namespace \"urn:test\";" " prefix t;" " anyxml e;" + " leaf l {" + " type string;" + " }" "}"; assert_int_equal(LY_SUCCESS, lys_parse_mem(ctx, yang, LYS_IN_YANG, NULL)); @@ -227,6 +230,14 @@ test_text(void **state) lyd_free_all(tree); tree = NULL; + /* characters following a reference must be copied from the input, not from their decoded code point */ + str = "<€𠜎Øn&|"; + assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, str, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); + assert_non_null(tree); + assert_string_equal("<€𠜎Øn&|", lyd_get_value(tree)); + lyd_free_all(tree); + tree = NULL; + /* test using n-bytes UTF8 hexadecimal code points */ str = ""; assert_int_equal(LY_SUCCESS, lyd_parse_data_mem(ctx, str, LYD_XML, 0, LYD_VALIDATE_PRESENT, &tree)); From af761528d48fb56a809f3c2d1e0b78010e7a98b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Fri, 27 Nov 2026 01:14:03 +0100 Subject: [PATCH 2/3] tests BUGFIX Windows load yang.dll next to the tests The tests link the shared yang library, but Windows has no rpath. It finds a DLL only next to the executable or on PATH, and neither covers where yang.dll is built. The tests are built into tests// while yang.dll ends up in /, so all of the tests died on startup with STATUS_DLL_NOT_FOUND (0xc0000135), after the build itself had already been fixed. The DLLs of the dependencies were not a problem as vcpkg copies those by itself. Co-Authored-By: Claude Sonnet 5.5 --- tests/CMakeLists.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f48fd11d6..f6e7d98d9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,6 +5,20 @@ configure_file("${PROJECT_SOURCE_DIR}/tests/tests_config.h.in" "${PROJECT_BINARY include_directories(SYSTEM ${CMOCKA_INCLUDE_DIR}) include_directories(${PROJECT_BINARY_DIR}/tests/) +if(WIN32 AND BUILD_SHARED_LIBS) + # There is no rpath on Windows + get_property(YANG_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(YANG_MULTI_CONFIG) + set(YANG_DLL_TESTS_DIR "${CMAKE_BINARY_DIR}/tests/$") + else() + set(YANG_DLL_TESTS_DIR "${CMAKE_BINARY_DIR}/tests") + endif() + add_custom_target(yang_dll_for_tests + COMMAND ${CMAKE_COMMAND} -E make_directory "${YANG_DLL_TESTS_DIR}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ "${YANG_DLL_TESTS_DIR}" + DEPENDS yang) +endif() + function(ly_add_utest) cmake_parse_arguments(ADDTEST "" "NAME;WRAP" "SOURCES" ${ARGN}) set(TEST_NAME utest_${ADDTEST_NAME}) @@ -15,6 +29,9 @@ function(ly_add_utest) add_executable(${TEST_NAME} ${TEST_SOURCES} ${compatsrc}) target_link_libraries(${TEST_NAME} yang ${CMOCKA_LIBRARIES}) + if(TARGET yang_dll_for_tests) + add_dependencies(${TEST_NAME} yang_dll_for_tests) + endif() # Set common attributes of all tests set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests") From 9c7028a6303358dffacba02e43e2f1db03b4c640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Fri, 27 Nov 2026 02:07:05 +0100 Subject: [PATCH 3/3] tests BUGFIX skip only the POSIX regex part of tpdf_reuse on Windows This entire test was being skipped on Windows. The only problematic part is actually the OpenConfig module because of its POSIX regular expression. This test was introduced by a fix for #2581, and the thing that's tested does not actually depend on the OpenConfig regex dialect. Let's not skip this entire test, and let's use an appropriate #ifdef for this. Co-Authored-By: Claude Sonnet 5.5 --- tests/utests/schema/test_tree_schema_compile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c index 0738d037e..252f39cdd 100644 --- a/tests/utests/schema/test_tree_schema_compile.c +++ b/tests/utests/schema/test_tree_schema_compile.c @@ -2284,6 +2284,7 @@ test_type_tpdf_reuse(void **state) CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, tree); UTEST_LOG_CTX_CLEAN; +#ifdef LY_HAVE_REGEX_H /* module with patterns and the OC extension */ str = "module i {yang-version 1.1; namespace urn:i; prefix i;" "import openconfig-extensions {prefix oc-ext;}" @@ -2303,6 +2304,7 @@ test_type_tpdf_reuse(void **state) data = "abc1"; CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree); lyd_free_all(tree); +#endif } static void @@ -4340,9 +4342,7 @@ main(void) UTEST(test_type_leafref, setup), UTEST(test_type_empty, setup), UTEST(test_type_union, setup), -#ifndef _WIN32 UTEST(test_type_tpdf_reuse, setup), -#endif UTEST(test_type_dflt, setup), UTEST(test_type_exts, setup), UTEST(test_status, setup),