Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3f1b09

Browse files
Issue #23815: Fixed crashes related to directly created instances of types in
_tkinter and curses.panel modules.
1 parent 4c35964 commit e3f1b09

5 files changed

Lines changed: 16 additions & 3 deletions

File tree

Lib/test/test_curses.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ def __del__(self):
285285
panel.set_userptr(A())
286286
panel.set_userptr(None)
287287

288+
def test_new_curses_panel(self):
289+
panel = curses.panel.new_panel(self.stdscr)
290+
self.assertRaises(TypeError, type(panel))
291+
288292
@unittest.skipUnless(hasattr(curses, 'resizeterm'),
289293
'resizeterm not available')
290294
def test_resize_term(self):

Lib/test/test_tcl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,8 @@ def test_splitdict(self):
649649
expected = {'a': (1, 2, 3), 'something': 'foo', 'status': ''}
650650
self.assertEqual(splitdict(tcl, arg), expected)
651651

652+
def test_new_tcl_obj(self):
653+
self.assertRaises(TypeError, _tkinter.Tcl_Obj)
652654

653655
class BigmemTclTest(unittest.TestCase):
654656

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ Core and Builtins
116116
Library
117117
-------
118118

119+
- Issue #23815: Fixed crashes related to directly created instances of types in
120+
_tkinter and curses.panel modules.
121+
119122
- Issue #17765: weakref.ref() no longer silently ignores keyword arguments.
120123
Patch by Georg Brandl.
121124

Modules/_curses_panel.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,11 @@ PyInit__curses_panel(void)
506506
d = PyModule_GetDict(m);
507507

508508
/* Initialize object type */
509-
_curses_panelstate(m)->PyCursesPanel_Type = \
510-
PyType_FromSpec(&PyCursesPanel_Type_spec);
511-
if (_curses_panelstate(m)->PyCursesPanel_Type == NULL)
509+
v = PyType_FromSpec(&PyCursesPanel_Type_spec);
510+
if (v == NULL)
512511
goto fail;
512+
((PyTypeObject *)v)->tp_new = NULL;
513+
_curses_panelstate(m)->PyCursesPanel_Type = v;
513514

514515
import_curses();
515516
if (PyErr_Occurred())

Modules/_tkinter.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,6 +3551,7 @@ PyInit__tkinter(void)
35513551
Py_DECREF(m);
35523552
return NULL;
35533553
}
3554+
((PyTypeObject *)o)->tp_new = NULL;
35543555
if (PyModule_AddObject(m, "TkappType", o)) {
35553556
Py_DECREF(o);
35563557
Py_DECREF(m);
@@ -3563,6 +3564,7 @@ PyInit__tkinter(void)
35633564
Py_DECREF(m);
35643565
return NULL;
35653566
}
3567+
((PyTypeObject *)o)->tp_new = NULL;
35663568
if (PyModule_AddObject(m, "TkttType", o)) {
35673569
Py_DECREF(o);
35683570
Py_DECREF(m);
@@ -3575,6 +3577,7 @@ PyInit__tkinter(void)
35753577
Py_DECREF(m);
35763578
return NULL;
35773579
}
3580+
((PyTypeObject *)o)->tp_new = NULL;
35783581
if (PyModule_AddObject(m, "Tcl_Obj", o)) {
35793582
Py_DECREF(o);
35803583
Py_DECREF(m);

0 commit comments

Comments
 (0)