diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-11-20 06:48:30 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-11-20 06:48:30 (GMT) |
commit | f6f15918087f2fae652634303a79f9cc6bc421ce (patch) | |
tree | 93cd0cfea2b6c6a142df1d337538c73b0003e960 /Modules | |
parent | 52d0eb2dc0728b68b1aaac06936d19a84ffe9a75 (diff) | |
parent | e20973926a2ec19c4b87e460dc6f0edb478ce352 (diff) | |
download | cpython-f6f15918087f2fae652634303a79f9cc6bc421ce.zip cpython-f6f15918087f2fae652634303a79f9cc6bc421ce.tar.gz cpython-f6f15918087f2fae652634303a79f9cc6bc421ce.tar.bz2 |
Issue #28715: Added error checks for PyUnicode_AsUTF8().
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/_ctypes.c | 5 | ||||
-rw-r--r-- | Modules/_ctypes/callproc.c | 4 | ||||
-rw-r--r-- | Modules/ossaudiodev.c | 9 |
3 files changed, 11 insertions, 7 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index b3a9581..65c950e 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -728,8 +728,7 @@ PyCStructType_setattro(PyObject *self, PyObject *key, PyObject *value) return -1; if (value && PyUnicode_Check(key) && - /* XXX struni _PyUnicode_AsString can fail (also in other places)! */ - 0 == strcmp(_PyUnicode_AsString(key), "_fields_")) + _PyUnicode_EqualToASCIIString(key, "_fields_")) return PyCStructUnionType_update_stgdict(self, value, 1); return 0; } @@ -743,7 +742,7 @@ UnionType_setattro(PyObject *self, PyObject *key, PyObject *value) return -1; if (PyUnicode_Check(key) && - 0 == strcmp(_PyUnicode_AsString(key), "_fields_")) + _PyUnicode_EqualToASCIIString(key, "_fields_")) return PyCStructUnionType_update_stgdict(self, value, 0); return 0; } diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index d3044f3..7d542fb 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -1666,7 +1666,9 @@ POINTER(PyObject *self, PyObject *cls) return result; } if (PyUnicode_CheckExact(cls)) { - char *name = _PyUnicode_AsString(cls); + const char *name = PyUnicode_AsUTF8(cls); + if (name == NULL) + return NULL; buf = PyMem_Malloc(strlen(name) + 3 + 1); if (buf == NULL) return PyErr_NoMemory(); diff --git a/Modules/ossaudiodev.c b/Modules/ossaudiodev.c index 4796203..5f0505c 100644 --- a/Modules/ossaudiodev.c +++ b/Modules/ossaudiodev.c @@ -929,11 +929,14 @@ static PyMethodDef oss_mixer_methods[] = { static PyObject * oss_getattro(oss_audio_t *self, PyObject *nameobj) { - char *name = ""; + const char *name = ""; PyObject * rval = NULL; - if (PyUnicode_Check(nameobj)) - name = _PyUnicode_AsString(nameobj); + if (PyUnicode_Check(nameobj)) { + name = PyUnicode_AsUTF8(nameobj); + if (name == NULL) + return NULL; + } if (strcmp(name, "closed") == 0) { rval = (self->fd == -1) ? Py_True : Py_False; |