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 /Python | |
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 'Python')
-rw-r--r-- | Python/ast.c | 8 | ||||
-rw-r--r-- | Python/importdl.c | 4 |
2 files changed, 9 insertions, 3 deletions
diff --git a/Python/ast.c b/Python/ast.c index 33b7df6..82f4529 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -2118,17 +2118,19 @@ ast_for_atom(struct compiling *c, const node *n) errtype = "value error"; if (errtype) { char buf[128]; + const char *s = NULL; PyObject *type, *value, *tback, *errstr; PyErr_Fetch(&type, &value, &tback); errstr = PyObject_Str(value); - if (errstr) { - char *s = _PyUnicode_AsString(errstr); + if (errstr) + s = PyUnicode_AsUTF8(errstr); + if (s) { PyOS_snprintf(buf, sizeof(buf), "(%s) %s", errtype, s); - Py_DECREF(errstr); } else { PyErr_Clear(); PyOS_snprintf(buf, sizeof(buf), "(%s) unknown error", errtype); } + Py_XDECREF(errstr); ast_error(c, n, buf); Py_DECREF(type); Py_XDECREF(value); diff --git a/Python/importdl.c b/Python/importdl.c index ac03289..f56fa94 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -147,6 +147,10 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp) /* Package context is needed for single-phase init */ oldcontext = _Py_PackageContext; _Py_PackageContext = PyUnicode_AsUTF8(name_unicode); + if (_Py_PackageContext == NULL) { + _Py_PackageContext = oldcontext; + goto error; + } m = p0(); _Py_PackageContext = oldcontext; |