libxml2-2.9.8-python3_hack-1.patch 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. Submitted By: Pierre Labastie <pierre dot labastie at neuf dot fr>
  2. Date: 2017-11-23
  3. Initial Package Version: 2.9.7
  4. Upstream Status: Bug reported (https://bugzilla.gnome.org/show_bug.cgi?id=789714)
  5. Origin: Jan Majetek/OpenSuse (https://bugzilla.opensuse.org/show_bug.cgi?id=1065270)
  6. Description: Fix a segfault in the Python 3 module. It is only a hack.
  7. Index: libxml2-2.9.5/python/libxml.c
  8. ===================================================================
  9. --- libxml2-2.9.5.orig/python/libxml.c
  10. +++ libxml2-2.9.5/python/libxml.c
  11. @@ -1620,6 +1620,7 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNU
  12. PyObject *message;
  13. PyObject *result;
  14. char str[1000];
  15. + unsigned char *ptr = (unsigned char *)str;
  16. #ifdef DEBUG_ERROR
  17. printf("libxml_xmlErrorFuncHandler(%p, %s, ...) called\n", ctx, msg);
  18. @@ -1636,12 +1637,20 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNU
  19. str[999] = 0;
  20. va_end(ap);
  21. +#if PY_MAJOR_VERSION >= 3
  22. + /* Ensure the error string doesn't start at UTF8 continuation. */
  23. + while (*ptr && (*ptr & 0xc0) == 0x80)
  24. + ptr++;
  25. +#endif
  26. +
  27. list = PyTuple_New(2);
  28. PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt);
  29. Py_XINCREF(libxml_xmlPythonErrorFuncCtxt);
  30. - message = libxml_charPtrConstWrap(str);
  31. + message = libxml_charPtrConstWrap(ptr);
  32. PyTuple_SetItem(list, 1, message);
  33. result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list);
  34. + /* Forget any errors caused in the error handler. */
  35. + PyErr_Clear();
  36. Py_XDECREF(list);
  37. Py_XDECREF(result);
  38. }