]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #26873: xmlrpc now raises ResponseError on unsupported type tags
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 4 May 2016 08:26:42 +0000 (11:26 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 4 May 2016 08:26:42 +0000 (11:26 +0300)
instead of silently return incorrect result.

Lib/test/test_xmlrpc.py
Lib/xmlrpc/client.py
Misc/NEWS

index 831a5a5aaed5fc546375f4e71888e24228f4467d..02d9f5c650c6f3b5d47c2a21fa208365f4a0c5ea 100644 (file)
@@ -224,6 +224,20 @@ class XMLRPCTestCase(unittest.TestCase):
             self.assertIs(type(newvalue), xmlrpclib.Binary)
             self.assertIsNone(m)
 
+    def test_loads_unsupported(self):
+        ResponseError = xmlrpclib.ResponseError
+        data = '<params><param><value><spam/></value></param></params>'
+        self.assertRaises(ResponseError, xmlrpclib.loads, data)
+        data = ('<params><param><value><array>'
+                '<value><spam/></value>'
+                '</array></value></param></params>')
+        self.assertRaises(ResponseError, xmlrpclib.loads, data)
+        data = ('<params><param><value><struct>'
+                '<member><name>a</name><value><spam/></value></member>'
+                '<member><name>b</name><value><spam/></value></member>'
+                '</struct></value></param></params>')
+        self.assertRaises(ResponseError, xmlrpclib.loads, data)
+
     def test_get_host_info(self):
         # see bug #3613, this raised a TypeError
         transp = xmlrpc.client.Transport()
index 551dce965267761c1ef9fde85827e60e6e4af0f9..bbf9ee63f7672834fc42644127961b29a506d581 100644 (file)
@@ -640,6 +640,7 @@ class Unmarshaller:
         self._stack = []
         self._marks = []
         self._data = []
+        self._value = False
         self._methodname = None
         self._encoding = "utf-8"
         self.append = self._stack.append
@@ -669,6 +670,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):
index 678fac1469ea6f6542cc1c745bda3a9bafc6d9ac..86b9789b3a11118bede4f747047c39d18441f42b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -107,6 +107,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #26873: xmlrpc now raises ResponseError on unsupported type tags
+  instead of silently return incorrect result.
+
 - Issue #26711: Fixed the comparison of plistlib.Data with other types.
 
 - Issue #24114: Fix an uninitialized variable in `ctypes.util`.