Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 398ef5c

Browse files
Issue python#29327: Fixed a crash when pass the iterable keyword argument to sorted().
1 parent a57a8a3 commit 398ef5c

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Lib/test/test_builtin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,16 @@ def test_basic(self):
16271627
self.assertEqual(data, sorted(copy, reverse=1))
16281628
self.assertNotEqual(data, copy)
16291629

1630+
def test_bad_arguments(self):
1631+
# Issue #29327: The first argument is positional-only.
1632+
sorted([])
1633+
with self.assertRaises(TypeError):
1634+
sorted(iterable=[])
1635+
# Other arguments are keyword-only
1636+
sorted([], key=None)
1637+
with self.assertRaises(TypeError):
1638+
sorted([], None)
1639+
16301640
def test_inputtypes(self):
16311641
s = 'abracadabra'
16321642
types = [list, tuple, str]

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.6.1 release candidate 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #29327: Fixed a crash when pass the iterable keyword argument to
14+
sorted().
15+
1316
- Issue #29034: Fix memory leak and use-after-free in os module (path_converter).
1417

1518
- Issue #29159: Fix regression in bytes(x) when x.__index__() raises Exception.

Python/bltinmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2123,7 +2123,7 @@ builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
21232123
{
21242124
PyObject *newlist, *v, *seq, *keyfunc=NULL, **newargs;
21252125
PyObject *callable;
2126-
static char *kwlist[] = {"iterable", "key", "reverse", 0};
2126+
static char *kwlist[] = {"", "key", "reverse", 0};
21272127
int reverse;
21282128
Py_ssize_t nargs;
21292129

@@ -2142,6 +2142,7 @@ builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
21422142
return NULL;
21432143
}
21442144

2145+
assert(PyTuple_GET_SIZE(args) >= 1);
21452146
newargs = &PyTuple_GET_ITEM(args, 1);
21462147
nargs = PyTuple_GET_SIZE(args) - 1;
21472148
v = _PyObject_FastCallDict(callable, newargs, nargs, kwds);

0 commit comments

Comments
 (0)