[Python-checkins] python/dist/src/Objects object.c,2.173,2.174

gvanrossum@sourceforge.net gvanrossum@sourceforge.net
Mon, 13 May 2002 11:29:48 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv8995/Objects

Modified Files:
	object.c 
Log Message:
Jim Fulton reported a segfault in dir().  A heavily proxied object
returned a proxy for __class__ whose __bases__ was also a proxy.  The
merge_class_dict() helper for dir() assumed incorrectly that __bases__
would always be a tuple and used the in-line tuple API on the proxy.

I will backport this to 2.2 as well.


Index: object.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
retrieving revision 2.173
retrieving revision 2.174
diff -C2 -d -r2.173 -r2.174
*** object.c	26 Apr 2002 02:46:00 -0000	2.173
--- object.c	13 May 2002 18:29:46 -0000	2.174
***************
*** 1521,1532 ****
  		PyErr_Clear();
  	else {
  		int i, n;
! 		assert(PyTuple_Check(bases));
! 		n = PyTuple_GET_SIZE(bases);
! 		for (i = 0; i < n; i++) {
! 			PyObject *base = PyTuple_GET_ITEM(bases, i);
! 			if (merge_class_dict(dict, base) < 0) {
! 				Py_DECREF(bases);
! 				return -1;
  			}
  		}
--- 1521,1540 ----
  		PyErr_Clear();
  	else {
+ 		/* We have no guarantee that bases is a real tuple */
  		int i, n;
! 		n = PySequence_Size(bases); /* This better be right */
! 		if (n < 0)
! 			PyErr_Clear();
! 		else {
! 			for (i = 0; i < n; i++) {
! 				PyObject *base = PySequence_GetItem(bases, i);
! 				if (base == NULL) {
! 					Py_DECREF(bases);
! 					return -1;
! 				}
! 				if (merge_class_dict(dict, base) < 0) {
! 					Py_DECREF(bases);
! 					return -1;
! 				}
  			}
  		}