changeset: 92399:7b7bae546959 parent: 92396:499b60b7d067 parent: 92398:6a96c28f9474 user: Serhiy Storchaka date: Thu Sep 11 10:58:02 2014 +0300 files: Lib/test/test_tcl.py Misc/NEWS Modules/_tkinter.c description: 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. diff -r 499b60b7d067 -r 7b7bae546959 Lib/test/test_tcl.py --- a/Lib/test/test_tcl.py Thu Sep 11 10:40:44 2014 +0300 +++ b/Lib/test/test_tcl.py Thu Sep 11 10:58:02 2014 +0300 @@ -418,7 +418,6 @@ self.assertEqual(passValue(['a', ['b', 'c']]), ('a', ('b', 'c')) if self.wantobjects else 'a {b c}') - @unittest.skipIf(sys.platform.startswith("aix"), 'Issue #21951: crashes on AIX') def test_user_command(self): result = None def testfunc(arg): @@ -446,9 +445,11 @@ check('string') check('string\xbd') check('string\u20ac') + check('') check(b'string', 'string') check(b'string\xe2\x82\xac', 'string\xe2\x82\xac') check(b'string\xbd', 'string\xbd') + check(b'', '') check('str\x00ing') check('str\x00ing\xbd') check('str\x00ing\u20ac') diff -r 499b60b7d067 -r 7b7bae546959 Misc/NEWS --- a/Misc/NEWS Thu Sep 11 10:40:44 2014 +0300 +++ b/Misc/NEWS Thu Sep 11 10:58:02 2014 +0300 @@ -132,6 +132,9 @@ Library ------- +- Issue #21951: Fixed a crash in Tkinter on AIX when called Tcl command with + empty string or tuple argument. + - Issue #21951: Tkinter now most likely raises MemoryError instead of crash if the memory allocation fails. diff -r 499b60b7d067 -r 7b7bae546959 Modules/_tkinter.c --- a/Modules/_tkinter.c Thu Sep 11 10:40:44 2014 +0300 +++ b/Modules/_tkinter.c Thu Sep 11 10:58:02 2014 +0300 @@ -906,6 +906,8 @@ Py_ssize_t size, i; size = PySequence_Fast_GET_SIZE(value); + if (size == 0) + return Tcl_NewListObj(0, NULL); if (!CHECK_SIZE(size, sizeof(Tcl_Obj *))) { PyErr_SetString(PyExc_OverflowError, PyTuple_Check(value) ? "tuple is too long" : @@ -936,6 +938,8 @@ inbuf = PyUnicode_DATA(value); size = PyUnicode_GET_LENGTH(value); + if (size == 0) + return Tcl_NewUnicodeObj((const void *)"", 0); if (!CHECK_SIZE(size, sizeof(Tcl_UniChar))) { PyErr_SetString(PyExc_OverflowError, "string is too long"); return NULL;