changeset: 106245:1827b64cfce8 branch: 3.6 parent: 106243:3452ff9e8f0a user: Serhiy Storchaka date: Fri Jan 20 08:33:06 2017 +0200 files: Lib/test/test_builtin.py Misc/NEWS Python/bltinmodule.c description: Issue #29327: Fixed a crash when pass the iterable keyword argument to sorted(). diff -r 3452ff9e8f0a -r 1827b64cfce8 Lib/test/test_builtin.py --- a/Lib/test/test_builtin.py Thu Jan 19 21:39:37 2017 -0800 +++ b/Lib/test/test_builtin.py Fri Jan 20 08:33:06 2017 +0200 @@ -1627,6 +1627,16 @@ self.assertEqual(data, sorted(copy, reverse=1)) self.assertNotEqual(data, copy) + def test_bad_arguments(self): + # Issue #29327: The first argument is positional-only. + sorted([]) + with self.assertRaises(TypeError): + sorted(iterable=[]) + # Other arguments are keyword-only + sorted([], key=None) + with self.assertRaises(TypeError): + sorted([], None) + def test_inputtypes(self): s = 'abracadabra' types = [list, tuple, str] diff -r 3452ff9e8f0a -r 1827b64cfce8 Misc/NEWS --- a/Misc/NEWS Thu Jan 19 21:39:37 2017 -0800 +++ b/Misc/NEWS Fri Jan 20 08:33:06 2017 +0200 @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #29327: Fixed a crash when pass the iterable keyword argument to + sorted(). + - Issue #29034: Fix memory leak and use-after-free in os module (path_converter). - Issue #29159: Fix regression in bytes(x) when x.__index__() raises Exception. diff -r 3452ff9e8f0a -r 1827b64cfce8 Python/bltinmodule.c --- a/Python/bltinmodule.c Thu Jan 19 21:39:37 2017 -0800 +++ b/Python/bltinmodule.c Fri Jan 20 08:33:06 2017 +0200 @@ -2123,7 +2123,7 @@ { PyObject *newlist, *v, *seq, *keyfunc=NULL, **newargs; PyObject *callable; - static char *kwlist[] = {"iterable", "key", "reverse", 0}; + static char *kwlist[] = {"", "key", "reverse", 0}; int reverse; Py_ssize_t nargs; @@ -2142,6 +2142,7 @@ return NULL; } + assert(PyTuple_GET_SIZE(args) >= 1); newargs = &PyTuple_GET_ITEM(args, 1); nargs = PyTuple_GET_SIZE(args) - 1; v = _PyObject_FastCallDict(callable, newargs, nargs, kwds);