summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-07-30 22:39:31 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-07-30 22:39:31 (GMT)
commit0eb1115f4415593861a85aad3c7d12081252c866 (patch)
treeaebb692dda8180fd4001f9dbba57f66b63a4e92b /Python/bltinmodule.c
parent3ce45389bd929296863e26586fa6963ba307e6fb (diff)
downloadcpython-0eb1115f4415593861a85aad3c7d12081252c866.zip
cpython-0eb1115f4415593861a85aad3c7d12081252c866.tar.gz
cpython-0eb1115f4415593861a85aad3c7d12081252c866.tar.bz2
Fix for SF byg [ #420304 ] getattr function w/ default
Fix suggested by Michael Hudson: Raise TypeError if attribute name passed to getattr() is not a string or Unicode. There is some unfortunate duplication of code between builtin_getattr() and PyObject_GetAttr(), but it appears to be unavoidable.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 362cdaa..571cfe2 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -890,6 +890,17 @@ builtin_getattr(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "OO|O:getattr", &v, &name, &dflt))
return NULL;
+ if (PyUnicode_Check(name)) {
+ name = _PyUnicode_AsDefaultEncodedString(name, NULL);
+ if (name == NULL)
+ return NULL;
+ }
+
+ if (!PyString_Check(name)) {
+ PyErr_SetString(PyExc_TypeError,
+ "attribute name must be string");
+ return NULL;
+ }
result = PyObject_GetAttr(v, name);
if (result == NULL && dflt != NULL) {
PyErr_Clear();