[Python-checkins] cpython (3.4): Issue #24683: Fixed crashes in _json functions called with arguments of
serhiy.storchaka
python-checkins at python.org
Sun Jul 26 08:04:39 CEST 2015
https://hg.python.org/cpython/rev/b3d0bf112f70
changeset: 97069:b3d0bf112f70
branch: 3.4
parent: 97062:e807f1d81cb6
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Jul 26 09:01:22 2015 +0300
summary:
Issue #24683: Fixed crashes in _json functions called with arguments of
inappropriate type.
files:
Lib/test/test_json/test_separators.py | 6 ++++++
Misc/NEWS | 3 +++
Modules/_json.c | 12 ++++++++++--
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_json/test_separators.py b/Lib/test/test_json/test_separators.py
--- a/Lib/test/test_json/test_separators.py
+++ b/Lib/test/test_json/test_separators.py
@@ -39,6 +39,12 @@
self.assertEqual(h2, h)
self.assertEqual(d2, expect)
+ def test_illegal_separators(self):
+ h = {1: 2, 3: 4}
+ self.assertRaises(TypeError, self.dumps, h, separators=(b', ', ': '))
+ self.assertRaises(TypeError, self.dumps, h, separators=(', ', b': '))
+ self.assertRaises(TypeError, self.dumps, h, separators=(b', ', b': '))
+
class TestPySeparators(TestSeparators, PyTest): pass
class TestCSeparators(TestSeparators, CTest): pass
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -66,6 +66,9 @@
Library
-------
+- Issue #24683: Fixed crashes in _json functions called with arguments of
+ inappropriate type.
+
- Issue #21697: shutil.copytree() now correctly handles symbolic links that
point to directories. Patch by Eduardo Seabra and Thomas Kluyver.
diff --git a/Modules/_json.c b/Modules/_json.c
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -1223,11 +1223,19 @@
assert(PyEncoder_Check(self));
s = (PyEncoderObject *)self;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOOOOOp:make_encoder", kwlist,
- &markers, &defaultfn, &encoder, &indent, &key_separator, &item_separator,
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOUUOOp:make_encoder", kwlist,
+ &markers, &defaultfn, &encoder, &indent,
+ &key_separator, &item_separator,
&sort_keys, &skipkeys, &allow_nan))
return -1;
+ if (markers != Py_None && !PyDict_Check(markers)) {
+ PyErr_Format(PyExc_TypeError,
+ "make_encoder() argument 1 must be dict or None, "
+ "not %.200s", Py_TYPE(markers)->tp_name);
+ return -1;
+ }
+
s->markers = markers;
s->defaultfn = defaultfn;
s->encoder = encoder;
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list