[ python-Bugs-1030557 ] PyMapping_Check crashes when argument is
NULL
SourceForge.net
noreply at sourceforge.net
Sun Sep 19 08:00:57 CEST 2004
Bugs item #1030557, was opened at 2004-09-18 23:22
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1030557&group_id=5470
Category: Python Interpreter Core
Group: Python 2.4
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Michiel de Hoon (mdehoon)
Assigned to: Raymond Hettinger (rhettinger)
Summary: PyMapping_Check crashes when argument is NULL
Initial Comment:
The function PyMapping_Check in Objects/abstract.c in
Python 2.4a3 is
int
PyMapping_Check(PyObject *o)
{
if (PyInstance_Check(o))
return PyObject_HasAttrString(o,
"__getitem__");
return o && o->ob_type->tp_as_mapping &&
o->ob_type->tp_as_mapping->mp_subscript &&
!(o->ob_type->tp_as_sequence &&
o->ob_type->tp_as_sequence->sq_slice);
}
where PyInstance_Check is #defined in
Include/classobject.h as
#define PyInstance_Check(op) ((op)->ob_type ==
&PyInstance_Type)
Hence, if the argument o of PyMapping_Check is NULL,
the function will crash. I first noticed this crash on
Cygwin.
The problem is that PyInstance_Check dereferences the
argument o before the check for o==NULL is made in the
return statement.
In Python 2.3.4, PyMapping_Check was
int
PyMapping_Check(PyObject *o)
{
return o && o->ob_type->tp_as_mapping &&
o->ob_type->tp_as_mapping->mp_subscript;
}
which checks for o==NULL correctly.
By the way, I am not sure if I am submitting this to
the correct category.
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-09-19 01:00
Message:
Logged In: YES
user_id=80475
It is not clear that this is actually a bug. Most of the
PY???_Check functions expect a non-NULL object. The C API
docs are silent on the subject.
However, in the spirit of defensive programming, I added the
early null checks back to PyMapping_Check and PySequence_Check.
Fixed and checked in as:
Objects/abstract.c 2.132
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1030557&group_id=5470
More information about the Python-bugs-list
mailing list