You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by iv...@apache.org on 2016/10/18 12:14:34 UTC

svn commit: r1765424 - /subversion/trunk/subversion/libsvn_subr/xml.c

Author: ivan
Date: Tue Oct 18 12:14:34 2016
New Revision: 1765424

URL: http://svn.apache.org/viewvc?rev=1765424&view=rev
Log:
Use XML_StopParser with Expat >= 1.95.8 to abort XML parsing in the middle
of parse buffer if svn_xml_signal_bailout() was called.

(Mostly copied from subversion/libsvn_ra_serf/xml.c)

* subversion/libsvn_subr/xml.c
  (XML_VERSION_AT_LEAST): New. Copied from subversion/libsvn_ra_serf/xml.c.
  (expat_start_handler, expat_end_handler, expat_data_handler): Call
   XML_StopParser() if SVN_PARSER->ERROR is not NULL.

Modified:
    subversion/trunk/subversion/libsvn_subr/xml.c

Modified: subversion/trunk/subversion/libsvn_subr/xml.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/xml.c?rev=1765424&r1=1765423&r2=1765424&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/xml.c (original)
+++ subversion/trunk/subversion/libsvn_subr/xml.c Tue Oct 18 12:14:34 2016
@@ -42,6 +42,14 @@
 #include <expat.h>
 #endif
 
+#ifndef XML_VERSION_AT_LEAST
+#define XML_VERSION_AT_LEAST(major,minor,patch)                  \
+(((major) < XML_MAJOR_VERSION)                                       \
+ || ((major) == XML_MAJOR_VERSION && (minor) < XML_MINOR_VERSION)    \
+ || ((major) == XML_MAJOR_VERSION && (minor) == XML_MINOR_VERSION && \
+     (patch) <= XML_MICRO_VERSION))
+#endif /* XML_VERSION_AT_LEAST */
+
 #ifdef XML_UNICODE
 #error Expat is unusable -- it has been compiled for wide characters
 #endif
@@ -345,6 +353,15 @@ static void expat_start_handler(void *us
   svn_xml_parser_t *svn_parser = userData;
 
   (*svn_parser->start_handler)(svn_parser->baton, name, atts);
+
+#if XML_VERSION_AT_LEAST(1, 95, 8)
+  /* Stop XML parsing if svn_xml_signal_bailout() was called.
+     We cannot do this in svn_xml_signal_bailout() because Expat
+     documentation states that XML_StopParser() must be called only from
+     callbacks. */
+  if (svn_parser->error)
+    (void) XML_StopParser(svn_parser->parser, 0 /* resumable */);
+#endif
 }
 
 static void expat_end_handler(void *userData, const XML_Char *name)
@@ -352,6 +369,15 @@ static void expat_end_handler(void *user
   svn_xml_parser_t *svn_parser = userData;
 
   (*svn_parser->end_handler)(svn_parser->baton, name);
+
+#if XML_VERSION_AT_LEAST(1, 95, 8)
+  /* Stop XML parsing if svn_xml_signal_bailout() was called.
+     We cannot do this in svn_xml_signal_bailout() because Expat
+     documentation states that XML_StopParser() must be called only from
+     callbacks. */
+  if (svn_parser->error)
+    (void) XML_StopParser(svn_parser->parser, 0 /* resumable */);
+#endif
 }
 
 static void expat_data_handler(void *userData, const XML_Char *s, int len)
@@ -359,6 +385,15 @@ static void expat_data_handler(void *use
   svn_xml_parser_t *svn_parser = userData;
 
   (*svn_parser->data_handler)(svn_parser->baton, s, (apr_size_t)len);
+
+#if XML_VERSION_AT_LEAST(1, 95, 8)
+  /* Stop XML parsing if svn_xml_signal_bailout() was called.
+     We cannot do this in svn_xml_signal_bailout() because Expat
+     documentation states that XML_StopParser() must be called only from
+     callbacks. */
+  if (svn_parser->error)
+    (void) XML_StopParser(svn_parser->parser, 0 /* resumable */);
+#endif
 }