[Python-checkins] CVS: python/dist/src/Modules _tkinter.c,1.100,1.101

A.M. Kuchling python-dev@python.org
Sun, 18 Jun 2000 17:55:12 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory slayer.i.sourceforge.net:/tmp/cvs-serv6640

Modified Files:
	_tkinter.c 
Log Message:
Patch from Michael Hudson to fix flatten recursive data structures:
[mwh21@atrus build]$ ./python
>>> import Tkinter
>>> l = []
>>> l.append(l)
>>> Tkinter._flatten(l)
Segmentation fault (core dumped)


Index: _tkinter.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_tkinter.c,v
retrieving revision 1.100
retrieving revision 1.101
diff -C2 -r1.100 -r1.101
*** _tkinter.c	2000/06/18 18:45:50	1.100
--- _tkinter.c	2000/06/19 00:55:09	1.101
***************
*** 2002,2006 ****
  
  static int
! _flatten1(FlattenContext* context, PyObject* item)
  {
  	/* add tuple or list to argument tuple (recursively) */
--- 2002,2006 ----
  
  static int
! _flatten1(FlattenContext* context, PyObject* item, int depth)
  {
  	/* add tuple or list to argument tuple (recursively) */
***************
*** 2008,2012 ****
  	int i, size;
  
! 	if (PyList_Check(item)) {
  		size = PyList_GET_SIZE(item);
  		/* preallocate (assume no nesting) */
--- 2008,2015 ----
  	int i, size;
  
! 	if (depth > 1000) {
! 		PyErr_SetString(PyExc_ValueError,"nesting too deep in _flatten");
! 		return 0;
! 	} else if (PyList_Check(item)) {
  		size = PyList_GET_SIZE(item);
  		/* preallocate (assume no nesting) */
***************
*** 2017,2021 ****
  			PyObject *o = PyList_GET_ITEM(item, i);
  			if (PyList_Check(o) || PyTuple_Check(o)) {
! 				if (!_flatten1(context, o))
  					return 0;
  			} else if (o != Py_None) {
--- 2020,2024 ----
  			PyObject *o = PyList_GET_ITEM(item, i);
  			if (PyList_Check(o) || PyTuple_Check(o)) {
! 				if (!_flatten1(context, o, depth + 1))
  					return 0;
  			} else if (o != Py_None) {
***************
*** 2034,2038 ****
  			PyObject *o = PyTuple_GET_ITEM(item, i);
  			if (PyList_Check(o) || PyTuple_Check(o)) {
! 				if (!_flatten1(context, o))
  					return 0;
  			} else if (o != Py_None) {
--- 2037,2041 ----
  			PyObject *o = PyTuple_GET_ITEM(item, i);
  			if (PyList_Check(o) || PyTuple_Check(o)) {
! 				if (!_flatten1(context, o, depth + 1))
  					return 0;
  			} else if (o != Py_None) {
***************
*** 2069,2073 ****
  	context.size = 0;
  
! 	if (!_flatten1(&context, item))
  		return NULL;
  
--- 2072,2076 ----
  	context.size = 0;
  
! 	if (!_flatten1(&context, item,0))
  		return NULL;