From ae62f015240c9162773341a9922794e6b960779d Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Sat, 6 Oct 2018 00:44:25 -0600 Subject: [PATCH] bpo-34910: Ensure that PyObject_Print() always returns -1 on error. (GH-9733) --- .../next/C API/2018-10-05-17-06-49.bpo-34910.tSFrls.rst | 2 ++ Objects/object.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/C API/2018-10-05-17-06-49.bpo-34910.tSFrls.rst diff --git a/Misc/NEWS.d/next/C API/2018-10-05-17-06-49.bpo-34910.tSFrls.rst b/Misc/NEWS.d/next/C API/2018-10-05-17-06-49.bpo-34910.tSFrls.rst new file mode 100644 index 00000000000..eff4755d8d5 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2018-10-05-17-06-49.bpo-34910.tSFrls.rst @@ -0,0 +1,2 @@ +Ensure that :c:func:`PyObject_Print` always returns ``-1`` on error. Patch +by Zackery Spytz. diff --git a/Objects/object.c b/Objects/object.c index 607f047d147..ab1baa70d43 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -375,8 +375,9 @@ PyObject_Print(PyObject *op, FILE *fp, int flags) else if (PyUnicode_Check(s)) { PyObject *t; t = PyUnicode_AsEncodedString(s, "utf-8", "backslashreplace"); - if (t == NULL) - ret = 0; + if (t == NULL) { + ret = -1; + } else { fwrite(PyBytes_AS_STRING(t), 1, PyBytes_GET_SIZE(t), fp);