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

Commit ed7910b

Browse files
author
Anselm Kruis
committed
Stackless issue #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 291583b commit ed7910b

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
@@ -344,6 +344,10 @@ PyTasklet_BindEx(PyTaskletObject *task, PyObject *func, PyObject *args, PyObject
344344

345345
if (func != NULL && !PyCallable_Check(func))
346346
TYPE_ERROR("tasklet function must be a callable or None", -1);
347+
if (args != NULL && !PyTuple_Check(args))
348+
TYPE_ERROR("tasklet args must be a tuple or None", -1);
349+
if (kwargs != NULL && !PyDict_Check(kwargs))
350+
TYPE_ERROR("tasklet kwargs must be a dictionary or None", -1);
347351
if (ts && ts->st.current == task) {
348352
RUNTIME_ERROR("can't (re)bind the current tasklet", -1);
349353
}

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)