[Expat-checkins] expat/tests runtests.c,1.35,1.36
Fred L. Drake
fdrake@users.sourceforge.net
Tue, 08 Oct 2002 10:04:58 -0700
Update of /cvsroot/expat/expat/tests
In directory usw-pr-cvs1:/tmp/cvs-serv11082/tests
Modified Files:
runtests.c
Log Message:
SF bug #620343: segfault: bad API/callback interaction
The start-namespace-decl callback can set the start-element callback to
NULL, but Expat tried to call it anyway.
Index: runtests.c
===================================================================
RCS file: /cvsroot/expat/expat/tests/runtests.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- runtests.c 30 Aug 2002 22:05:55 -0000 1.35
+++ runtests.c 8 Oct 2002 17:04:55 -0000 1.36
@@ -790,6 +790,41 @@
}
END_TEST
+
+/* Regression test for SF bug #620343. */
+static void
+start_element_fail(void *userData,
+ const XML_Char *name, const XML_Char **atts)
+{
+ /* We should never get here. */
+ fail("should never reach start_element_fail()");
+}
+
+static void
+start_ns_clearing_start_element(void *userData,
+ const XML_Char *prefix,
+ const XML_Char *uri)
+{
+ XML_SetStartElementHandler((XML_Parser) userData, NULL);
+}
+
+START_TEST(test_start_ns_clears_start_element)
+{
+ /* This needs to use separate start/end tags; using the empty tag
+ syntax doesn't cause the problematic path through Expat to be
+ taken.
+ */
+ char *text = "<e xmlns='http://xml.libexpat.org/'></e>";
+
+ XML_SetStartElementHandler(parser, start_element_fail);
+ XML_SetStartNamespaceDeclHandler(parser, start_ns_clearing_start_element);
+ XML_UseParserAsHandlerArg(parser);
+ if (XML_Parse(parser, text, strlen(text), 1) == XML_STATUS_ERROR)
+ xml_failure(parser);
+}
+END_TEST
+
+
static Suite *
make_basic_suite(void)
{
@@ -835,6 +870,7 @@
tcase_add_test(tc_namespace, test_return_ns_triplet);
tcase_add_test(tc_namespace, test_ns_tagname_overwrite);
tcase_add_test(tc_namespace, test_ns_tagname_overwrite_triplet);
+ tcase_add_test(tc_namespace, test_start_ns_clears_start_element);
return s;
}