From 9b7b361695a83edb798fa037e40ee7e83d6024f1 Mon Sep 17 00:00:00 2001 From: Charalampos Stratakis Date: Mon, 16 Jul 2018 17:58:08 +0200 Subject: [PATCH] Fix segfaults resulting from incorrect memory management. --- fix-segfaults.patch | 48 +++++++++++++++++++++++++++++++++++++++++++++ itstool.spec | 10 +++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 fix-segfaults.patch diff --git a/fix-segfaults.patch b/fix-segfaults.patch new file mode 100644 index 0000000..e76dd2e --- /dev/null +++ b/fix-segfaults.patch @@ -0,0 +1,48 @@ +diff --git a/itstool.in b/itstool.in +index c1d0585..a16eba9 100755 +--- a/itstool.in ++++ b/itstool.in +@@ -477,6 +477,7 @@ class Document (object): + if load_dtd: + ctxt.loadSubset(1) + if keep_entities: ++ ctxt.loadSubset(1) + ctxt.ctxtUseOptions(libxml2.XML_PARSE_DTDLOAD) + ctxt.replaceEntities(0) + else: +@@ -1043,6 +1044,7 @@ class Document (object): + if self._load_dtd: + ctxt.loadSubset(1) + if self._keep_entities: ++ ctxt.loadSubset(1) + ctxt.ctxtUseOptions(libxml2.XML_PARSE_DTDLOAD) + ctxt.replaceEntities(0) + else: +@@ -1069,7 +1071,9 @@ class Document (object): + ph_node = msg.get_placeholder(child.name).node + if self.has_child_elements(ph_node): + self.merge_translations(translations, None, ph_node, strict=strict) +- child.replaceNode(ph_node) ++ newnode = ph_node.copyNode(1) ++ newnode.setTreeDoc(self._doc) ++ child.replaceNode(newnode) + else: + repl = self.get_translated(ph_node, translations, strict=strict, lang=lang) + child.replaceNode(repl) +@@ -1084,10 +1088,15 @@ class Document (object): + (lang + ' ') if lang is not None else '', + msgstr.encode('utf-8'))) + self._xml_err = '' ++ ctxt.doc().freeDoc() + return node + retnode = node.copyNode(2) ++ retnode.setTreeDoc(self._doc) + for child in xml_child_iter(trnode): +- retnode.addChild(child.copyNode(1)) ++ newnode = child.copyNode(1) ++ newnode.setTreeDoc(self._doc) ++ retnode.addChild(newnode) ++ + ctxt.doc().freeDoc() + return retnode + diff --git a/itstool.spec b/itstool.spec index 3326d5a..f3db6e6 100644 --- a/itstool.spec +++ b/itstool.spec @@ -1,11 +1,15 @@ Name: itstool Version: 2.0.4 -Release: 3%{?dist} +Release: 4%{?dist} Summary: ITS-based XML translation tool License: GPLv3+ URL: http://itstool.org/ Source0: http://files.itstool.org/itstool/%{name}-%{version}.tar.bz2 +# An issue with libxml2 is causing segfaults for packages using +# itstool. Backported the workaround from upstream. +# https://github.com/itstool/itstool/commit/9b84c007a73e8275ca45762f1bfa3ab7c3a852e2 +Patch0: fix-segfaults.patch BuildArch: noarch @@ -20,6 +24,7 @@ how to separate it into PO file messages. %prep %setup -q +%patch0 -p1 %build export PYTHON=%{__python3} @@ -37,6 +42,9 @@ make install DESTDIR=$RPM_BUILD_ROOT %doc %{_mandir}/man1/itstool.1.gz %changelog +* Mon Jul 16 2018 Charalampos Stratakis - 2.0.4-4 +- Fix libxml2 related segfaults + * Mon Jul 16 2018 Miro HronĨok - 2.0.4-3 - Switch to Python 3