summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorchgnrdv <52372310+chgnrdv@users.noreply.github.com>2023-05-23 20:01:17 (GMT)
committerGitHub <noreply@github.com>2023-05-23 20:01:17 (GMT)
commit13b5d79090cdca138ca340de88f57e02279faf6d (patch)
treed77c14c281222ac945bd1676ae4b13e306444191 /Modules
parentae00b810d1d3ad7f1f7e226b02ece37c986330e7 (diff)
downloadcpython-13b5d79090cdca138ca340de88f57e02279faf6d.zip
cpython-13b5d79090cdca138ca340de88f57e02279faf6d.tar.gz
cpython-13b5d79090cdca138ca340de88f57e02279faf6d.tar.bz2
Fix missing/incomplete NULL checks in multiple source files (#104564)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_zoneinfo.c10
-rw-r--r--Modules/errnomodule.c1
-rw-r--r--Modules/posixmodule.c4
-rw-r--r--Modules/sha1module.c3
-rw-r--r--Modules/zlibmodule.c3
5 files changed, 20 insertions, 1 deletions
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
index c8c791b..0dcdb4d 100644
--- a/Modules/_zoneinfo.c
+++ b/Modules/_zoneinfo.c
@@ -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);
diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c
index fddde96..3d0c2d7 100644
--- a/Modules/errnomodule.c
+++ b/Modules/errnomodule.c
@@ -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) {
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 531f26b..2fe9973 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -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);
diff --git a/Modules/sha1module.c b/Modules/sha1module.c
index c66269b..ef8e067 100644
--- a/Modules/sha1module.c
+++ b/Modules/sha1module.c
@@ -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;
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index b67844a..534d065 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -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;