diff options
author | Guido van Rossum <guido@python.org> | 2007-08-27 23:24:46 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-08-27 23:24:46 (GMT) |
commit | 7d5baac81ce7617bc70f721b0ad90e95391063bb (patch) | |
tree | 7a3ed5e848ecd0a50d2cdb151a84e22c40d047f6 /Modules/posixmodule.c | |
parent | 26d95c3d07eb0893c7867d935d61a0fb7be43f2d (diff) | |
download | cpython-7d5baac81ce7617bc70f721b0ad90e95391063bb.zip cpython-7d5baac81ce7617bc70f721b0ad90e95391063bb.tar.gz cpython-7d5baac81ce7617bc70f721b0ad90e95391063bb.tar.bz2 |
posix.confname(): enforce that names as str instances.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 98b125c..4e6e0c5 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -5441,7 +5441,7 @@ struct constdef { static int conv_confname(PyObject *arg, int *valuep, struct constdef *table, - size_t tablesize) + size_t tablesize) { if (PyInt_Check(arg)) { *valuep = PyInt_AS_LONG(arg); @@ -5450,16 +5450,20 @@ conv_confname(PyObject *arg, int *valuep, struct constdef *table, else { /* look up the value in the table using a binary search */ size_t lo = 0; - size_t mid; + size_t mid; size_t hi = tablesize; int cmp; const char *confname; Py_ssize_t namelen; - if (PyObject_AsCharBuffer(arg, &confname, &namelen) < 0) { + if (!PyUnicode_Check(arg)) { PyErr_SetString(PyExc_TypeError, "configuration names must be strings or integers"); return 0; } + confname = PyUnicode_AsString(arg); + if (confname == NULL) + return 0; + namelen = strlen(confname); while (lo < hi) { mid = (lo + hi) / 2; cmp = strcmp(confname, table[mid].name); |