summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-06-23 14:36:32 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-06-23 14:36:32 (GMT)
commit99a8f90874c978147e6660896b93a5af27108b10 (patch)
tree3db3f34714b81c644fe123f8ab8429a560455820 /Objects
parent8caad49c30d2f9ecd09c8838bb691360e40c2665 (diff)
downloadcpython-99a8f90874c978147e6660896b93a5af27108b10.zip
cpython-99a8f90874c978147e6660896b93a5af27108b10.tar.gz
cpython-99a8f90874c978147e6660896b93a5af27108b10.tar.bz2
raise TypeError when PyObject_Get/SetAttr called with non-string name
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/Objects/object.c b/Objects/object.c
index ab9d4ed..5560792 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -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;
}