Skip to content

Commit 4b54e5e

Browse files
author
benjamin.peterson
committed
make _tkinter._flatten check the result of PySequence_Size for errors #3880
git-svn-id: http://svn.python.org/projects/python/trunk@69113 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent c322a7b commit 4b54e5e

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

Lib/test/test_tcl.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
import unittest
44
import os
5+
import _tkinter
56
from test import test_support
67
from Tkinter import Tcl
78
from _tkinter import TclError
89

10+
11+
class TkinterTest(unittest.TestCase):
12+
13+
def testFlattenLen(self):
14+
# flatten(<object with no length>)
15+
self.assertRaises(TypeError, _tkinter._flatten, True)
16+
17+
918
class TclTest(unittest.TestCase):
1019

1120
def setUp(self):
@@ -151,7 +160,7 @@ def testLoadTkFailure(self):
151160
os.environ['DISPLAY'] = old_display
152161

153162
def test_main():
154-
test_support.run_unittest(TclTest)
163+
test_support.run_unittest(TclTest, TkinterTest)
155164

156165
if __name__ == "__main__":
157166
test_main()

Modules/_tkinter.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2908,7 +2908,9 @@ Tkinter_Flatten(PyObject* self, PyObject* args)
29082908
return NULL;
29092909

29102910
context.maxsize = PySequence_Size(item);
2911-
if (context.maxsize <= 0)
2911+
if (context.maxsize < 0)
2912+
return NULL;
2913+
if (context.maxsize == 0)
29122914
return PyTuple_New(0);
29132915

29142916
context.tuple = PyTuple_New(context.maxsize);

0 commit comments

Comments
 (0)