]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix some missing null checks. (GH-118721)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 10 May 2024 09:51:57 +0000 (11:51 +0200)
committerGitHub <noreply@github.com>
Fri, 10 May 2024 09:51:57 +0000 (09:51 +0000)
(cherry picked from commit 7e6fcab20003b07621dc02ea78d6ea2fda500371)

Co-authored-by: Steve Dower <steve.dower@python.org>
Objects/typeobject.c
PC/launcher2.c

index 7776ae2b735c2b66012f66d2b9b25c08b061b742..0a21ec8dbb54afa7fd72b1a9e259d1b8b58a2a1d 100644 (file)
@@ -5470,15 +5470,19 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
             return NULL;
         }
         comma_w_quotes_sep = PyUnicode_FromString("', '");
+        if (!comma_w_quotes_sep) {
+            Py_DECREF(sorted_methods);
+            return NULL;
+        }
         joined = PyUnicode_Join(comma_w_quotes_sep, sorted_methods);
-        method_count = PyObject_Length(sorted_methods);
-        Py_DECREF(sorted_methods);
+        Py_DECREF(comma_w_quotes_sep);
         if (joined == NULL)  {
-            Py_DECREF(comma_w_quotes_sep);
+            Py_DECREF(sorted_methods);
             return NULL;
         }
+        method_count = PyObject_Length(sorted_methods);
+        Py_DECREF(sorted_methods);
         if (method_count == -1) {
-            Py_DECREF(comma_w_quotes_sep);
             Py_DECREF(joined);
             return NULL;
         }
@@ -5490,7 +5494,6 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
                      method_count > 1 ? "s" : "",
                      joined);
         Py_DECREF(joined);
-        Py_DECREF(comma_w_quotes_sep);
         return NULL;
     }
     PyObject *obj = type->tp_alloc(type, 0);
index b0a557784c4df0a86fb2e5cfc217e82c11b1fa13..c38cbc83a7ac0fc88c5ecc236c8bbf65b435a65a 100644 (file)
@@ -2681,6 +2681,11 @@ process(int argc, wchar_t ** argv)
     DWORD len = GetEnvironmentVariableW(L"PYLAUNCHER_LIMIT_TO_COMPANY", NULL, 0);
     if (len > 1) {
         wchar_t *limitToCompany = allocSearchInfoBuffer(&search, len);
+        if (!limitToCompany) {
+            exitCode = RC_NO_MEMORY;
+            winerror(0, L"Failed to allocate internal buffer");
+            goto abort;
+        }
         search.limitToCompany = limitToCompany;
         if (0 == GetEnvironmentVariableW(L"PYLAUNCHER_LIMIT_TO_COMPANY", limitToCompany, len)) {
             exitCode = RC_INTERNAL_ERROR;