]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-34910: Ensure that PyObject_Print() always returns -1 on error. (GH-9733)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 6 Oct 2018 07:06:53 +0000 (00:06 -0700)
committerGitHub <noreply@github.com>
Sat, 6 Oct 2018 07:06:53 +0000 (00:06 -0700)
(cherry picked from commit ae62f015240c9162773341a9922794e6b960779d)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Misc/NEWS.d/next/C API/2018-10-05-17-06-49.bpo-34910.tSFrls.rst [new file with mode: 0644]
Objects/object.c

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 (file)
index 0000000..eff4755
--- /dev/null
@@ -0,0 +1,2 @@
+Ensure that :c:func:`PyObject_Print` always returns ``-1`` on error.  Patch
+by Zackery Spytz.
index defff5579699e11c79849bca431d8c446ae29c0f..fdd41a61681f6411c608b705e92b16a4a98908de 100644 (file)
@@ -387,8 +387,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);