diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-11-20 06:47:21 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-11-20 06:47:21 (GMT) |
commit | 144f77a981ecad8884e1a4e70db72e6fdb609103 (patch) | |
tree | 259b8fadf04eb9fc07b7fae95d8164ea75847fd5 /Python | |
parent | 93ff8725b3f678586fbbc19d3d4b615b218300ff (diff) | |
download | cpython-144f77a981ecad8884e1a4e70db72e6fdb609103.zip cpython-144f77a981ecad8884e1a4e70db72e6fdb609103.tar.gz cpython-144f77a981ecad8884e1a4e70db72e6fdb609103.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 5b7ed7c..d36a9b7 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -2024,16 +2024,18 @@ 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 { 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 1aa585d..ea4f0e7 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; |