diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-01-20 08:35:18 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-01-20 08:35:18 +0200 |
commit | 299dc239fe79b06a7a270d0d9e3208f66f69d5b3 (patch) | |
tree | 35727ea35db2a17aca1edb530e4cb51526defcd2 | |
parent | aecbef408d178d387fabfb0eda28e3f0221c9dd7 (diff) | |
parent | 398ef5c08feabfdbf7d0b1e10817139f0e98eefd (diff) | |
download | cpython-git-299dc239fe79b06a7a270d0d9e3208f66f69d5b3.tar.gz |
Issue #29327: Fixed a crash when pass the iterable keyword argument to sorted().
-rw-r--r-- | Lib/test/test_builtin.py | 10 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Python/bltinmodule.c | 3 |
3 files changed, 15 insertions, 1 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index a792099f10..416316c028 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1627,6 +1627,16 @@ class TestSorted(unittest.TestCase): 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] @@ -10,6 +10,9 @@ What's New in Python 3.7.0 alpha 1? 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 --git a/Python/bltinmodule.c b/Python/bltinmodule.c index ab029ce0aa..6df8af4733 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -2128,7 +2128,7 @@ builtin_sorted(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwna { PyObject *newlist, *v, *seq, *keyfunc=NULL; PyObject *callable; - static const char * const kwlist[] = {"iterable", "key", "reverse", 0}; + static const char * const kwlist[] = {"", "key", "reverse", 0}; /* args 1-3 should match listsort in Objects/listobject.c */ static _PyArg_Parser parser = {"O|Oi:sorted", kwlist, 0}; int reverse; @@ -2147,6 +2147,7 @@ builtin_sorted(PyObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwna return NULL; } + assert(nargs >= 1); v = _PyObject_FastCallKeywords(callable, args + 1, nargs - 1, kwnames); Py_DECREF(callable); if (v == NULL) { |