summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-11-20 06:48:07 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-11-20 06:48:07 (GMT)
commite20973926a2ec19c4b87e460dc6f0edb478ce352 (patch)
treecc6843f8f0088c5ee37239afb65faaa0064654c2 /Python/ast.c
parent3c38e066b1a0e600575b2c72207b0f1ac85073cc (diff)
parent144f77a981ecad8884e1a4e70db72e6fdb609103 (diff)
downloadcpython-e20973926a2ec19c4b87e460dc6f0edb478ce352.zip
cpython-e20973926a2ec19c4b87e460dc6f0edb478ce352.tar.gz
cpython-e20973926a2ec19c4b87e460dc6f0edb478ce352.tar.bz2
Issue #28715: Added error checks for PyUnicode_AsUTF8().
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c8
1 files changed, 5 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);