lslebodn / rpms / libxml2

Forked from rpms/libxml2 4 years ago
Clone
53286c5
Index: libxml2-2.9.5/python/libxml.c
53286c5
===================================================================
53286c5
--- libxml2-2.9.5.orig/python/libxml.c
53286c5
+++ libxml2-2.9.5/python/libxml.c
53286c5
@@ -1620,6 +1620,7 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNU
53286c5
     PyObject *message;
53286c5
     PyObject *result;
53286c5
     char str[1000];
53286c5
+    unsigned char *ptr = (unsigned char *)str;
53286c5
 
53286c5
 #ifdef DEBUG_ERROR
53286c5
     printf("libxml_xmlErrorFuncHandler(%p, %s, ...) called\n", ctx, msg);
53286c5
@@ -1636,12 +1637,20 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNU
53286c5
 	    str[999] = 0;
53286c5
         va_end(ap);
53286c5
 
53286c5
+#if PY_MAJOR_VERSION >= 3
53286c5
+        /* Ensure the error string doesn't start at UTF8 continuation. */
53286c5
+        while (*ptr && (*ptr & 0xc0) == 0x80)
53286c5
+            ptr++;
53286c5
+#endif
53286c5
+
53286c5
         list = PyTuple_New(2);
53286c5
         PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt);
53286c5
         Py_XINCREF(libxml_xmlPythonErrorFuncCtxt);
53286c5
-        message = libxml_charPtrConstWrap(str);
53286c5
+        message = libxml_charPtrConstWrap(ptr);
53286c5
         PyTuple_SetItem(list, 1, message);
53286c5
         result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list);
53286c5
+        /* Forget any errors caused in the error handler. */
53286c5
+        PyErr_Clear();
53286c5
         Py_XDECREF(list);
53286c5
         Py_XDECREF(result);
53286c5
     }