Skip to content

Commit 17c0178

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 1c09c0e commit 17c0178

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
@@ -429,7 +429,6 @@ def passValue(value):
429429
self.assertEqual(passValue((1, '2', (3.4,))),
430430
(1, '2', (3.4,)) if self.wantobjects else '1 2 3.4')
431431

432-
@unittest.skipIf(sys.platform.startswith("aix"), 'Issue #21951: crashes on AIX')
433432
def test_user_command(self):
434433
result = []
435434
def testfunc(arg):
@@ -456,9 +455,11 @@ def float_eq(actual, expected):
456455
check('string')
457456
check('string\xbd')
458457
check('string\xe2\x82\xac', u'string\u20ac')
458+
check('')
459459
check(u'string')
460460
check(u'string\xbd')
461461
check(u'string\u20ac')
462+
check(u'')
462463
check('str\xc0\x80ing', u'str\x00ing')
463464
check('str\xc0\x80ing\xe2\x82\xac', u'str\x00ing\u20ac')
464465
check(u'str\x00ing')

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Core and Builtins
2222
Library
2323
-------
2424

25+
- Issue #21951: Fixed a crash in Tkinter on AIX when called Tcl command with
26+
empty string or tuple argument.
27+
2528
- Issue #21951: Tkinter now most likely raises MemoryError instead of crash
2629
if the memory allocation fails.
2730

Modules/_tkinter.c

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

10541054
size = PyTuple_Size(value);
1055+
if (size == 0)
1056+
return Tcl_NewListObj(0, NULL);
10551057
if (!CHECK_SIZE(size, sizeof(Tcl_Obj *))) {
10561058
PyErr_SetString(PyExc_OverflowError, "tuple is too long");
10571059
return NULL;
@@ -1075,6 +1077,8 @@ AsObj(PyObject *value)
10751077
Tcl_UniChar *outbuf = NULL;
10761078
Py_ssize_t i;
10771079
size_t allocsize;
1080+
if (size == 0)
1081+
return Tcl_NewUnicodeObj((const void *)"", 0);
10781082
if (!CHECK_SIZE(size, sizeof(Tcl_UniChar))) {
10791083
PyErr_SetString(PyExc_OverflowError, "string is too long");
10801084
return NULL;

0 commit comments

Comments
 (0)