summaryrefslogblamecommitdiff
path: root/system/libxml2/python-segfault-fix.patch
blob: f1f7554eb37991ed625e68aef969e1510c5153ab (plain) (tree)



































                                                                                              
Upstream: https://bugzilla.gnome.org/show_bug.cgi?id=791691

From d1ea6250dd00a3b7a92b52a743ec53f7751196e5 Mon Sep 17 00:00:00 2001
From: "A. Wilcox" <AWilcox@Wilcox-Tech.com>
Date: Sat, 16 Dec 2017 19:22:23 -0600
Subject: [PATCH] Python: if message is NULL, use Py_None instead

If the error message is malformed / invalid UTF-8, and the Python 3
binding is being used, then message may be NULL.  This will cause the
Python interpreter to crash (Segmentation fault) trying to unpack the
argument list into local variables.

This uses Py_None for message if message is NULL, so that the
interpreter does not crash.
---
 python/libxml.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/python/libxml.c b/python/libxml.c
index 5b1ff6e8..dae77b88 100644
--- a/python/libxml.c
+++ b/python/libxml.c
@@ -1640,6 +1640,10 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg,
         PyTuple_SetItem(list, 0, libxml_xmlPythonErrorFuncCtxt);
         Py_XINCREF(libxml_xmlPythonErrorFuncCtxt);
         message = libxml_charPtrConstWrap(str);
+        if (message == NULL) {
+            Py_INCREF(Py_None);
+            message = Py_None;
+        }
         PyTuple_SetItem(list, 1, message);
         result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list);
         Py_XDECREF(list);
-- 
2.14.1