]> granicus.if.org Git - libexpat/commitdiff
Test that unrecognised encodings are rejected
authorRhodri James <rhodri@kynesim.co.uk>
Wed, 1 Feb 2017 14:51:23 +0000 (14:51 +0000)
committerSebastian Pipping <sebastian@pipping.org>
Sat, 18 Feb 2017 16:58:16 +0000 (17:58 +0100)
expat/tests/runtests.c

index 79368dd61fee9575ffb893e687dcf262af7d3423..74fb1c91a4bd283fc008612f99d1ecae6b52c380 100644 (file)
@@ -855,6 +855,37 @@ START_TEST(test_unknown_encoding_internal_entity)
 }
 END_TEST
 
+/* Test unrecognised encoding handler */
+static void dummy_release(void *UNUSED_P(data))
+{
+}
+
+static int XMLCALL
+UnrecognisedEncodingHandler(void *UNUSED_P(data),
+                            const XML_Char *UNUSED_P(encoding),
+                            XML_Encoding *info)
+{
+    info->data = NULL;
+    info->convert = NULL;
+    info->release = dummy_release;
+    return XML_STATUS_ERROR;
+}
+
+START_TEST(test_unrecognised_encoding_internal_entity)
+{
+    const char *text =
+        "<?xml version='1.0' encoding='unsupported-encoding'?>\n"
+        "<!DOCTYPE test [<!ENTITY foo 'bar'>]>\n"
+        "<test a='&foo;'/>";
+
+    XML_SetUnknownEncodingHandler(parser,
+                                  UnrecognisedEncodingHandler,
+                                  NULL);
+    if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text), XML_TRUE) != XML_STATUS_ERROR)
+        fail("Unrecognised encoding not rejected");
+}
+END_TEST
+
 /* Regression test for SF bug #620106. */
 static int XMLCALL
 external_entity_loader_set_encoding(XML_Parser parser,
@@ -1871,10 +1902,6 @@ START_TEST(test_alloc_ns)
 }
 END_TEST
 
-static void dummy_release(void *UNUSED_P(data))
-{
-}
-
 static int XMLCALL
 unknown_released_encoding_handler(void *UNUSED_P(data),
                                   const XML_Char *encoding,
@@ -1971,6 +1998,7 @@ make_suite(void)
     tcase_add_test(tc_basic, test_attr_whitespace_normalization);
     tcase_add_test(tc_basic, test_xmldecl_misplaced);
     tcase_add_test(tc_basic, test_unknown_encoding_internal_entity);
+    tcase_add_test(tc_basic, test_unrecognised_encoding_internal_entity);
     tcase_add_test(tc_basic,
                    test_wfc_undeclared_entity_unread_external_subset);
     tcase_add_test(tc_basic, test_wfc_undeclared_entity_no_external_subset);