[Python-checkins] cpython (3.5): Issue #26873: xmlrpc now raises ResponseError on unsupported type tags

serhiy.storchaka python-checkins at python.org
Wed May 4 04:28:35 EDT 2016


https://hg.python.org/cpython/rev/0d015f6aba8b
changeset:   101221:0d015f6aba8b
branch:      3.5
parent:      101217:194b356c84f5
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Wed May 04 11:26:42 2016 +0300
summary:
  Issue #26873: xmlrpc now raises ResponseError on unsupported type tags
instead of silently return incorrect result.

files:
  Lib/test/test_xmlrpc.py |  14 ++++++++++++++
  Lib/xmlrpc/client.py    |   3 +++
  Misc/NEWS               |   3 +++
  3 files changed, 20 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -224,6 +224,20 @@
             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()
diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py
--- a/Lib/xmlrpc/client.py
+++ b/Lib/xmlrpc/client.py
@@ -640,6 +640,7 @@
         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 @@
         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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -107,6 +107,9 @@
 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`.

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list