Skip to content

Commit 13b5d79

Browse files
chgnrdvarhadthedev
andauthored
Fix missing/incomplete NULL checks in multiple source files (#104564)
Co-authored-by: Oleg Iarygin <[email protected]>
1 parent ae00b81 commit 13b5d79

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

Modules/_zoneinfo.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -2381,7 +2381,12 @@ get_local_timestamp(PyObject *dt, int64_t *local_ts)
23812381
/////
23822382
// Functions for cache handling
23832383

2384-
/* Constructor for StrongCacheNode */
2384+
/* Constructor for StrongCacheNode
2385+
*
2386+
* This function doesn't set MemoryError if PyMem_Malloc fails,
2387+
* as the cache intentionally doesn't propagate exceptions
2388+
* and fails silently if error occurs.
2389+
*/
23852390
static StrongCacheNode *
23862391
strong_cache_node_new(PyObject *key, PyObject *zone)
23872392
{
@@ -2572,6 +2577,9 @@ update_strong_cache(zoneinfo_state *state, const PyTypeObject *const type,
25722577
}
25732578

25742579
StrongCacheNode *new_node = strong_cache_node_new(key, zone);
2580+
if (new_node == NULL) {
2581+
return;
2582+
}
25752583
StrongCacheNode **root = &(state->ZONEINFO_STRONG_CACHE);
25762584
move_strong_cache_node_to_front(state, root, new_node);
25772585

Modules/errnomodule.c

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ errno_exec(PyObject *module)
8484
PyObject *module_dict = PyModule_GetDict(module);
8585
PyObject *error_dict = PyDict_New();
8686
if (!module_dict || !error_dict) {
87+
Py_XDECREF(error_dict);
8788
return -1;
8889
}
8990
if (PyDict_SetItemString(module_dict, "errorcode", error_dict) < 0) {

Modules/posixmodule.c

+4
Original file line numberDiff line numberDiff line change
@@ -9023,6 +9023,10 @@ os_setgroups(PyObject *module, PyObject *groups)
90239023
}
90249024

90259025
gid_t *grouplist = PyMem_New(gid_t, len);
9026+
if (grouplist == NULL) {
9027+
PyErr_NoMemory();
9028+
return NULL;
9029+
}
90269030
for (Py_ssize_t i = 0; i < len; i++) {
90279031
PyObject *elem;
90289032
elem = PySequence_GetItem(groups, i);

Modules/sha1module.c

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ static SHA1object *
7373
newSHA1object(SHA1State *st)
7474
{
7575
SHA1object *sha = (SHA1object *)PyObject_GC_New(SHA1object, st->sha1_type);
76+
if (sha == NULL) {
77+
return NULL;
78+
}
7679
sha->lock = NULL;
7780
PyObject_GC_Track(sha);
7881
return sha;

Modules/zlibmodule.c

+3
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,9 @@ ZlibDecompressor__new__(PyTypeObject *cls,
17221722
return NULL;
17231723
}
17241724
ZlibDecompressor *self = PyObject_New(ZlibDecompressor, cls);
1725+
if (self == NULL) {
1726+
return NULL;
1727+
}
17251728
self->eof = 0;
17261729
self->needs_input = 1;
17271730
self->avail_in_real = 0;

0 commit comments

Comments
 (0)