From b3619be995f9c4080dc38f2a8532bdf44503d840 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 30 Jan 2009 02:24:39 +0000 Subject: make _tkinter._flatten check the result of PySequence_Size for errors #3880 --- Lib/test/test_tcl.py | 11 ++++++++++- Modules/_tkinter.c | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_tcl.py b/Lib/test/test_tcl.py index fa170ef..26e294c 100644 --- a/Lib/test/test_tcl.py +++ b/Lib/test/test_tcl.py @@ -2,10 +2,19 @@ import unittest import os +import _tkinter from test import test_support from Tkinter import Tcl from _tkinter import TclError + +class TkinterTest(unittest.TestCase): + + def testFlattenLen(self): + # flatten() + self.assertRaises(TypeError, _tkinter._flatten, True) + + class TclTest(unittest.TestCase): def setUp(self): @@ -151,7 +160,7 @@ class TclTest(unittest.TestCase): os.environ['DISPLAY'] = old_display def test_main(): - test_support.run_unittest(TclTest) + test_support.run_unittest(TclTest, TkinterTest) if __name__ == "__main__": test_main() diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index 93e7edc..6e89f2f 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -2908,7 +2908,9 @@ Tkinter_Flatten(PyObject* self, PyObject* args) return NULL; context.maxsize = PySequence_Size(item); - if (context.maxsize <= 0) + if (context.maxsize < 0) + return NULL; + if (context.maxsize == 0) return PyTuple_New(0); context.tuple = PyTuple_New(context.maxsize); -- cgit v0.12