From a9aaf85cfc3025b7013b5adc4bef2ce32ecc7fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20Eren=20=C3=9Cr=C3=BCn?= Date: Tue, 23 Sep 2025 12:12:50 +0200 Subject: [PATCH] tests: Add line/column checks to async entity tests CVE: CVE-2024-8176 Upstream-Status: Backport [https://github.com/libexpat/libexpat/pull/1059] Signed-off-by: Peter Marko --- tests/misc_tests.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/misc_tests.c b/tests/misc_tests.c index 19f41df7..7a4d2455 100644 --- a/tests/misc_tests.c +++ b/tests/misc_tests.c @@ -644,6 +644,8 @@ START_TEST(test_misc_async_entity_rejected) { const char *doc; enum XML_Status expectedStatusNoGE; enum XML_Error expectedErrorNoGE; + XML_Size expectedErrorLine; + XML_Size expectedErrorColumn; }; const struct test_case cases[] = { // Opened by one entity, closed by another @@ -652,35 +654,35 @@ START_TEST(test_misc_async_entity_rejected) { " '>\n" "]>\n" "&open;&close;\n", - XML_STATUS_OK, XML_ERROR_NONE}, + XML_STATUS_OK, XML_ERROR_NONE, 5, 4}, // Opened by tag, closed by entity (non-root case) {"\n" " '>\n" "]>\n" "&g1;\n", - XML_STATUS_ERROR, XML_ERROR_TAG_MISMATCH}, + XML_STATUS_ERROR, XML_ERROR_TAG_MISMATCH, 5, 8}, // Opened by tag, closed by entity (root case) {"\n" " '>\n" "]>\n" "&g1;\n", - XML_STATUS_ERROR, XML_ERROR_NO_ELEMENTS}, + XML_STATUS_ERROR, XML_ERROR_NO_ELEMENTS, 5, 4}, // Opened by entity, closed by tag <-- regression from 2.7.0 {"\n" " &g0;'>\n" "]>\n" "&g1;\n", - XML_STATUS_ERROR, XML_ERROR_TAG_MISMATCH}, + XML_STATUS_ERROR, XML_ERROR_TAG_MISMATCH, 5, 4}, // Opened by tag, closed by entity; then the other way around {"'>\n" " '>\n" "]>\n" "&close;&open;\n", - XML_STATUS_OK, XML_ERROR_NONE}, + XML_STATUS_OK, XML_ERROR_NONE, 5, 8}, }; for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { @@ -701,6 +703,11 @@ START_TEST(test_misc_async_entity_rejected) { /*isFinal=*/XML_TRUE) == expectedStatus); assert_true(XML_GetErrorCode(parser) == expectedError); +#if XML_GE == 1 + assert_true(XML_GetCurrentLineNumber(parser) == testCase.expectedErrorLine); + assert_true(XML_GetCurrentColumnNumber(parser) + == testCase.expectedErrorColumn); +#endif XML_ParserFree(parser); } }