]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
posix.confname(): enforce that names as str instances.
authorGuido van Rossum <guido@python.org>
Mon, 27 Aug 2007 23:24:46 +0000 (23:24 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 27 Aug 2007 23:24:46 +0000 (23:24 +0000)
Modules/posixmodule.c

index 98b125c8453832adec5f5946c854340bf21dde58..4e6e0c595db2a889f0eae5617f9816b70d59ebbe 100644 (file)
@@ -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);