]> granicus.if.org Git - python/commitdiff
Issue #21951: Fixed a crash in Tkinter on AIX when called Tcl command with
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 11 Sep 2014 07:56:59 +0000 (10:56 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 11 Sep 2014 07:56:59 +0000 (10:56 +0300)
empty string or tuple argument.

On some platforms Tcl memory allocator returns NULL when allocating zero-sized
block of memory.

Lib/test/test_tcl.py
Misc/NEWS
Modules/_tkinter.c

index d627034cf34999c6782281c297b473dc35081857..5836989df81e66877e0ee97bbc40183187c81a95 100644 (file)
@@ -429,7 +429,6 @@ class TclTest(unittest.TestCase):
         self.assertEqual(passValue((1, '2', (3.4,))),
                          (1, '2', (3.4,)) if self.wantobjects else '1 2 3.4')
 
-    @unittest.skipIf(sys.platform.startswith("aix"), 'Issue #21951: crashes on AIX')
     def test_user_command(self):
         result = []
         def testfunc(arg):
@@ -456,9 +455,11 @@ class TclTest(unittest.TestCase):
         check('string')
         check('string\xbd')
         check('string\xe2\x82\xac', u'string\u20ac')
+        check('')
         check(u'string')
         check(u'string\xbd')
         check(u'string\u20ac')
+        check(u'')
         check('str\xc0\x80ing', u'str\x00ing')
         check('str\xc0\x80ing\xe2\x82\xac', u'str\x00ing\u20ac')
         check(u'str\x00ing')
index 9e5e681a55133be0ae3bd368b017d0cefaa58738..2b0ac047b136346823d5281e34f9baff895d5080 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -22,6 +22,9 @@ Core and Builtins
 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.
 
index d0a4464716b838b9c9854ac06730ec9b90d60ce5..acc0110984a7234829312bfde593076488a4b32d 100644 (file)
@@ -1052,6 +1052,8 @@ AsObj(PyObject *value)
         Py_ssize_t size, i;
 
         size = PyTuple_Size(value);
+        if (size == 0)
+            return Tcl_NewListObj(0, NULL);
         if (!CHECK_SIZE(size, sizeof(Tcl_Obj *))) {
             PyErr_SetString(PyExc_OverflowError, "tuple is too long");
             return NULL;
@@ -1075,6 +1077,8 @@ AsObj(PyObject *value)
         Tcl_UniChar *outbuf = NULL;
         Py_ssize_t i;
         size_t allocsize;
+        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;