]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-34435: Add missing NULL check to unicode_encode_ucs1(). (GH-8823)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 19 Aug 2018 20:19:18 +0000 (16:19 -0400)
committerGitHub <noreply@github.com>
Sun, 19 Aug 2018 20:19:18 +0000 (16:19 -0400)
Reported by Svace static analyzer.
(cherry picked from commit 74a307d48ef8b278c4629ca0ef2139be1c9a34e6)

Co-authored-by: Alexey Izbyshev <izbyshev@users.noreply.github.com>
Objects/unicodeobject.c

index bed7d419b0701f7af0abde9c9325b9babbaf86c0..972423e78da8c41d13e6be988abede495e29c3a7 100644 (file)
@@ -6903,8 +6903,6 @@ unicode_encode_ucs1(PyObject *unicode,
                     str = _PyBytesWriter_WriteBytes(&writer, str,
                                                     PyBytes_AS_STRING(rep),
                                                     PyBytes_GET_SIZE(rep));
-                    if (str == NULL)
-                        goto onError;
                 }
                 else {
                     assert(PyUnicode_Check(rep));
@@ -6940,6 +6938,9 @@ unicode_encode_ucs1(PyObject *unicode,
                         }
                     }
                 }
+                if (str == NULL)
+                    goto onError;
+
                 pos = newpos;
                 Py_CLEAR(rep);
             }