Skip to content

Commit 117de2b

Browse files
committed
fix(security)(_imagingtk.c): unsafe pointer dereference from unchecked python i
In `_tkinit`, `PyLong_AsVoidPtr(arg)` converts an arbitrary Python object to a `void*` pointer which is then cast to `Tcl_Interp*` and passed to `TkImaging_Init`. If `PyLong_AsVoidPtr` fails (returns NULL and sets an error), or if the caller passes an arbitrary integer value, the code proceeds to dereference it without any validation, potentially leading to a crash or arbitrary memory access. Affected files: _imagingtk.c Signed-off-by: Trần Bách <45133811+barttran2k@users.noreply.github.com>
1 parent c722aae commit 117de2b

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/_imagingtk.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ _tkinit(PyObject *self, PyObject *args) {
3333
}
3434

3535
interp = (Tcl_Interp *)PyLong_AsVoidPtr(arg);
36+
if (interp == NULL && PyErr_Occurred()) {
37+
return NULL;
38+
}
3639

37-
/* This will bomb if interp is invalid... */
3840
TkImaging_Init(interp);
3941

4042
Py_RETURN_NONE;

0 commit comments

Comments
 (0)