]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix missing/incomplete NULL checks in multiple source files (#104564)
authorchgnrdv <52372310+chgnrdv@users.noreply.github.com>
Tue, 23 May 2023 20:01:17 +0000 (23:01 +0300)
committerGitHub <noreply@github.com>
Tue, 23 May 2023 20:01:17 +0000 (14:01 -0600)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Modules/_zoneinfo.c
Modules/errnomodule.c
Modules/posixmodule.c
Modules/sha1module.c
Modules/zlibmodule.c

index c8c791b6d7c0d88c9c9ea7ccc39653c49d7d6eab..0dcdb4da47d5dbd2dea8b828d24b405331b7cccc 100644 (file)
@@ -2381,7 +2381,12 @@ get_local_timestamp(PyObject *dt, int64_t *local_ts)
 /////
 // Functions for cache handling
 
-/* Constructor for StrongCacheNode */
+/* Constructor for StrongCacheNode
+ *
+ * This function doesn't set MemoryError if PyMem_Malloc fails,
+ * as the cache intentionally doesn't propagate exceptions
+ * and fails silently if error occurs.
+ */
 static StrongCacheNode *
 strong_cache_node_new(PyObject *key, PyObject *zone)
 {
@@ -2572,6 +2577,9 @@ update_strong_cache(zoneinfo_state *state, const PyTypeObject *const type,
     }
 
     StrongCacheNode *new_node = strong_cache_node_new(key, zone);
+    if (new_node == NULL) {
+        return;
+    }
     StrongCacheNode **root = &(state->ZONEINFO_STRONG_CACHE);
     move_strong_cache_node_to_front(state, root, new_node);
 
index fddde960a5fe9a3bef14c46ca4ca3250d4caccb4..3d0c2d7ae945bceccee553e203c498d1be5bc374 100644 (file)
@@ -84,6 +84,7 @@ errno_exec(PyObject *module)
     PyObject *module_dict = PyModule_GetDict(module);
     PyObject *error_dict = PyDict_New();
     if (!module_dict || !error_dict) {
+        Py_XDECREF(error_dict);
         return -1;
     }
     if (PyDict_SetItemString(module_dict, "errorcode", error_dict) < 0) {
index 531f26ba8bc86fdb0651b440ffd54341c6ece330..2fe9973ef5bf7aa3a7fd5eb790baf3951b3485e0 100644 (file)
@@ -9023,6 +9023,10 @@ os_setgroups(PyObject *module, PyObject *groups)
     }
 
     gid_t *grouplist = PyMem_New(gid_t, len);
+    if (grouplist == NULL) {
+        PyErr_NoMemory();
+        return NULL;
+    }
     for (Py_ssize_t i = 0; i < len; i++) {
         PyObject *elem;
         elem = PySequence_GetItem(groups, i);
index c66269b5f5cdf3b2fc1d31d947d44b3f94c8885f..ef8e067dd337b3269114096f19c072ab111487d4 100644 (file)
@@ -73,6 +73,9 @@ static SHA1object *
 newSHA1object(SHA1State *st)
 {
     SHA1object *sha = (SHA1object *)PyObject_GC_New(SHA1object, st->sha1_type);
+    if (sha == NULL) {
+        return NULL;
+    }
     sha->lock = NULL;
     PyObject_GC_Track(sha);
     return sha;
index b67844a67c315c4f9b99ceb3f6786f189689cfba..534d065765f0f9dd67556af6267a9921799b6369 100644 (file)
@@ -1722,6 +1722,9 @@ ZlibDecompressor__new__(PyTypeObject *cls,
         return NULL;
     }
     ZlibDecompressor *self = PyObject_New(ZlibDecompressor, cls);
+    if (self == NULL) {
+        return NULL;
+    }
     self->eof = 0;
     self->needs_input = 1;
     self->avail_in_real = 0;