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

Skip to content

Commit dea7637

Browse files
Issue #23815: Fixed crashes related to directly created instances of types in
_tkinter and curses.panel modules.
2 parents 1ce738e + e3f1b09 commit dea7637

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
@@ -265,6 +265,9 @@ Core and Builtins
265265
Library
266266
-------
267267

268+
- Issue #23815: Fixed crashes related to directly created instances of types in
269+
_tkinter and curses.panel modules.
270+
268271
- Issue #17765: weakref.ref() no longer silently ignores keyword arguments.
269272
Patch by Georg Brandl.
270273

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
@@ -3544,6 +3544,7 @@ PyInit__tkinter(void)
35443544
Py_DECREF(m);
35453545
return NULL;
35463546
}
3547+
((PyTypeObject *)o)->tp_new = NULL;
35473548
if (PyModule_AddObject(m, "TkappType", o)) {
35483549
Py_DECREF(o);
35493550
Py_DECREF(m);
@@ -3556,6 +3557,7 @@ PyInit__tkinter(void)
35563557
Py_DECREF(m);
35573558
return NULL;
35583559
}
3560+
((PyTypeObject *)o)->tp_new = NULL;
35593561
if (PyModule_AddObject(m, "TkttType", o)) {
35603562
Py_DECREF(o);
35613563
Py_DECREF(m);
@@ -3568,6 +3570,7 @@ PyInit__tkinter(void)
35683570
Py_DECREF(m);
35693571
return NULL;
35703572
}
3573+
((PyTypeObject *)o)->tp_new = NULL;
35713574
if (PyModule_AddObject(m, "Tcl_Obj", o)) {
35723575
Py_DECREF(o);
35733576
Py_DECREF(m);

0 commit comments

Comments
 (0)