Skip to content

Commit c07c8ad

Browse files
author
Anselm Kruis
committed
Stackless issue python#245: check argument types of PyTasklet_BindEx
Check the arguments 'args' and 'kwargs'. This affects also tasklet.__init__() and tasklet.bind(). (cherry picked from commit ed31277)
1 parent 77521e2 commit c07c8ad

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

Stackless/changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ What's New in Stackless 3.X.X?
99

1010
*Release date: 20XX-XX-XX*
1111

12+
- https://github.com/stackless-dev/stackless/issues/245
13+
Prevent a crash, if you call tasklet.__init__() or tasklet.bind() with wrong
14+
argument types.
15+
1216
- https://github.com/stackless-dev/stackless/issues/241
1317
Prevent a crash, if you call tasklet.__setstate__() on a tasklet, that is
1418
alive.

Stackless/module/taskletobject.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ PyTasklet_BindEx(PyTaskletObject *task, PyObject *func, PyObject *args, PyObject
291291

292292
if (func != NULL && !PyCallable_Check(func))
293293
TYPE_ERROR("tasklet function must be a callable or None", -1);
294+
if (args != NULL && !PyTuple_Check(args))
295+
TYPE_ERROR("tasklet args must be a tuple or None", -1);
296+
if (kwargs != NULL && !PyDict_Check(kwargs))
297+
TYPE_ERROR("tasklet kwargs must be a dictionary or None", -1);
294298
if (ts && ts->st.current == task) {
295299
RUNTIME_ERROR("can't (re)bind the current tasklet", -1);
296300
}

Stackless/unittests/test_defects.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,15 @@ def test_setstate_alive(self):
663663
self.assertRaisesRegex(RuntimeError, "tasklet is alive", t.__setstate__, state)
664664

665665

666+
class TestTaskletBindArgumentTypes(StacklessTestCase):
667+
# a test case for https://github.com/stackless-dev/stackless/issues/245
668+
def test_bind_args(self):
669+
self.assertRaisesRegex(TypeError, "tasklet args must be a tuple or None", stackless.tasklet, lambda:None, 123)
670+
671+
def test_bind_kwargs(self):
672+
self.assertRaisesRegex(TypeError, "tasklet kwargs must be a dictionary or None", stackless.tasklet, lambda:None, None, 456)
673+
674+
666675
if __name__ == '__main__':
667676
if not sys.argv[1:]:
668677
sys.argv.append('-v')

0 commit comments

Comments
 (0)