From: Serhiy Storchaka Date: Wed, 4 May 2016 08:28:09 +0000 (+0300) Subject: Issue #26873: xmlrpclib now raises ResponseError on unsupported type tags X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=073418af05eca9a1747b9a89814285907b92a671;p=python Issue #26873: xmlrpclib now raises ResponseError on unsupported type tags instead of silently return incorrect result. --- diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index ca8d5d8cc0..97d9e8f789 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -208,6 +208,20 @@ class XMLRPCTestCase(unittest.TestCase): self.assertEqual(s, "abc \xc2\x95") self.assertEqual(items, [("def \xc2\x96", "ghi \xc2\x97")]) + def test_loads_unsupported(self): + ResponseError = xmlrpclib.ResponseError + data = '' + self.assertRaises(ResponseError, xmlrpclib.loads, data) + data = ('' + '' + '') + self.assertRaises(ResponseError, xmlrpclib.loads, data) + data = ('' + 'a' + 'b' + '') + self.assertRaises(ResponseError, xmlrpclib.loads, data) + class HelperTestCase(unittest.TestCase): def test_escape(self): diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py index 3a2c0bf38f..e072f71a3a 100644 --- a/Lib/xmlrpclib.py +++ b/Lib/xmlrpclib.py @@ -784,6 +784,7 @@ class Unmarshaller: self._stack = [] self._marks = [] self._data = [] + self._value = False self._methodname = None self._encoding = "utf-8" self.append = self._stack.append @@ -814,6 +815,8 @@ class Unmarshaller: if tag == "array" or tag == "struct": self._marks.append(len(self._stack)) self._data = [] + if self._value and tag not in self.dispatch: + raise ResponseError("unknown tag %r" % tag) self._value = (tag == "value") def data(self, text): diff --git a/Misc/NEWS b/Misc/NEWS index e521ae1488..88f7486203 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -77,6 +77,9 @@ Core and Builtins Library ------- +- Issue #26873: xmlrpclib now raises ResponseError on unsupported type tags + instead of silently return incorrect result. + - Issue #24114: Fix an uninitialized variable in `ctypes.util`. The bug only occurs on SunOS when the ctypes implementation searches