[Patches] PyObject_GetAttr/PyObject_SetAttr core dumps if given
non-string names
M.-A. Lemburg
mal@lemburg.com
Fri, 23 Jun 2000 12:06:45 +0200
Gisle Aas wrote:
>
> This is a modified patch that should address you latest suggestions:
This one looks ok to me.
Anyone else have an opinion on this patch ?
> Regards,
> Gisle
>
> Index: Objects/object.c
> ===================================================================
> RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
> retrieving revision 2.71
> diff -u -p -u -r2.71 object.c
> --- Objects/object.c 2000/06/09 16:20:39 2.71
> +++ Objects/object.c 2000/06/23 09:50:07
> @@ -600,8 +600,13 @@ PyObject_GetAttr(v, name)
> {
> if (v->ob_type->tp_getattro != NULL)
> return (*v->ob_type->tp_getattro)(v, name);
> - else
> - return PyObject_GetAttrString(v, PyString_AsString(name));
> +
> + if (!PyString_Check(name)) {
> + PyErr_SetString(PyExc_TypeError,
> + "attribute name must be string");
> + return NULL;
> + }
> + return PyObject_GetAttrString(v, PyString_AS_STRING(name));
> }
>
> int
> @@ -626,12 +631,19 @@ PyObject_SetAttr(v, name, value)
> {
> int err;
> Py_INCREF(name);
> - PyString_InternInPlace(&name);
> + if (PyString_Check(name))
> + PyString_InternInPlace(&name);
> if (v->ob_type->tp_setattro != NULL)
> err = (*v->ob_type->tp_setattro)(v, name, value);
> - else
> + else if (PyString_Check(name)) {
> err = PyObject_SetAttrString(
> - v, PyString_AsString(name), value);
> + v, PyString_AS_STRING(name), value);
> + }
> + else {
> + PyErr_SetString(PyExc_TypeError,
> + "attribute name must be string");
> + err = -1;
> + }
> Py_DECREF(name);
> return err;
> }
>
> I confirm that, to the best of my knowledge and belief, this
> contribution is free of any claims of third parties under
> copyright, patent or other rights or interests ("claims"). To
> the extent that I have any such claims, I hereby grant to CNRI a
> nonexclusive, irrevocable, royalty-free, worldwide license to
> reproduce, distribute, perform and/or display publicly, prepare
> derivative versions, and otherwise use this contribution as part
> of the Python software and its related documentation, or any
> derivative versions thereof, at no cost to CNRI or its licensed
> users, and to authorize others to do so.
>
> I acknowledge that CNRI may, at its sole discretion, decide
> whether or not to incorporate this contribution in the Python
> software and its related documentation. I further grant CNRI
> permission to use my name and other identifying information
> provided to CNRI by me for use in connection with the Python
> software and its related documentation.
--
Marc-Andre Lemburg
______________________________________________________________________
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/