[Python-bugs-list] [ python-Bugs-683726 ] METH_CLASS allows binding to the wrong class

SourceForge.net noreply@sourceforge.net
Sun, 09 Feb 2003 19:38:36 -0800


Bugs item #683726, was opened at 2003-02-09 18:21
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=683726&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Greg Chapman (glchapman)
Assigned to: Nobody/Anonymous (nobody)
Summary: METH_CLASS allows binding to the wrong class

Initial Comment:
I just noticed that this doesn't raise an exception:

>>> cmeth = dict.__dict__['fromkeys'].__get__(None, 
list)
>>> cmeth
<built-in method fromkeys of type object at 
0x1E0BB2E0>
>>> cmeth.__self__
<type 'list'>

Looking over the various METH_CLASS 
implementations, it doesn't look like they depend on the 
first (cls) parameter being of any particular type, but it 
might be nice to flag something like the above with an 
exception.

Also, there's this:

>>> cmeth2 = dict.__dict__['fromkeys'].__get__(None, 
42)
>>> cmeth2
<built-in method fromkeys of int object at 0x0074FD90>
>>> print cmeth2.__self__
42

Above, 42 gets passed through to classmethod_get in 
the type parameter, despite the fact that this parameter 
is typed as a PyTypeObject *. Perhpas wrap_descr_get 
should check that its second parameter (if it gets one) is 
a type?
 

----------------------------------------------------------------------

>Comment By: Greg Chapman (glchapman)
Date: 2003-02-09 18:38

Message:
Logged In: YES 
user_id=86307

I just realized that the above can be used to crash python, so 
I believe some sort of checking has to be added to 
classmethod_get:

>>> cmeth = dict.__dict__['fromkeys'].__get__(None)
>>> cmeth(4)

(above causes and access violation because the cls object 
passed to the fromkeys method is NULL).


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=683726&group_id=5470