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

Skip to content

Commit abf68ce

Browse files
Issue #21951: Fixed a crash in Tkinter on AIX when called Tcl command with
empty string or tuple argument. On some platforms Tcl memory allocator returns NULL when allocating zero-sized block of memory.
1 parent 0794088 commit abf68ce

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

Lib/test/test_tcl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ def passValue(value):
416416
self.assertEqual(passValue((1, '2', (3.4,))),
417417
(1, '2', (3.4,)) if self.wantobjects else '1 2 3.4')
418418

419-
@unittest.skipIf(sys.platform.startswith("aix"), 'Issue #21951: crashes on AIX')
420419
def test_user_command(self):
421420
result = None
422421
def testfunc(arg):
@@ -444,9 +443,11 @@ def float_eq(actual, expected):
444443
check('string')
445444
check('string\xbd')
446445
check('string\u20ac')
446+
check('')
447447
check(b'string', 'string')
448448
check(b'string\xe2\x82\xac', 'string\xe2\x82\xac')
449449
check(b'string\xbd', 'string\xbd')
450+
check(b'', '')
450451
check('str\x00ing')
451452
check('str\x00ing\xbd')
452453
check('str\x00ing\u20ac')

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Core and Builtins
3232
Library
3333
-------
3434

35+
- Issue #21951: Fixed a crash in Tkinter on AIX when called Tcl command with
36+
empty string or tuple argument.
37+
3538
- Issue #21951: Tkinter now most likely raises MemoryError instead of crash
3639
if the memory allocation fails.
3740

Modules/_tkinter.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,8 @@ AsObj(PyObject *value)
899899
Py_ssize_t size, i;
900900

901901
size = PyTuple_Size(value);
902+
if (size == 0)
903+
return Tcl_NewListObj(0, NULL);
902904
if (!CHECK_SIZE(size, sizeof(Tcl_Obj *))) {
903905
PyErr_SetString(PyExc_OverflowError, "tuple is too long");
904906
return NULL;
@@ -925,6 +927,8 @@ AsObj(PyObject *value)
925927

926928
inbuf = PyUnicode_DATA(value);
927929
size = PyUnicode_GET_LENGTH(value);
930+
if (size == 0)
931+
return Tcl_NewUnicodeObj((const void *)"", 0);
928932
if (!CHECK_SIZE(size, sizeof(Tcl_UniChar))) {
929933
PyErr_SetString(PyExc_OverflowError, "string is too long");
930934
return NULL;

0 commit comments

Comments
 (0)