changeset: 97071:7de4abf4eed2 parent: 97067:1be4d7388279 parent: 97070:ef4d09399b99 user: Serhiy Storchaka date: Sun Jul 26 09:03:16 2015 +0300 files: Misc/NEWS description: Issue #24683: Fixed crashes in _json functions called with arguments of inappropriate type. diff -r 1be4d7388279 -r 7de4abf4eed2 Lib/test/test_json/test_separators.py --- a/Lib/test/test_json/test_separators.py Sun Jul 26 06:50:51 2015 +1200 +++ b/Lib/test/test_json/test_separators.py Sun Jul 26 09:03:16 2015 +0300 @@ -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 -r 1be4d7388279 -r 7de4abf4eed2 Misc/NEWS --- a/Misc/NEWS Sun Jul 26 06:50:51 2015 +1200 +++ b/Misc/NEWS Sun Jul 26 09:03:16 2015 +0300 @@ -60,6 +60,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 -r 1be4d7388279 -r 7de4abf4eed2 Modules/_json.c --- a/Modules/_json.c Sun Jul 26 06:50:51 2015 +1200 +++ b/Modules/_json.c Sun Jul 26 09:03:16 2015 +0300 @@ -1344,11 +1344,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;