10000 Fix missing/incomplete NULL checks in multiple source files by chgnrdv · Pull Request #104564 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Fix missing/incomplete NULL checks in multiple source files #104564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix missing/incomplete NULL checks in multiple source files
* `Modules/_cursesmodule.c:_curses_initscr_impl`: pass `screen_encoding` to `PyCursesWindowObject` constructor instead of assigning it to field with possible NULL dereference
* `Modules/_zoneinfo.c:update_strong_cache`: check `new_node` value for NULL
* `Modules/errnomodule.c:errno_exec`: prevent leak of `error_dict` reference in case if `module_dict` is NULL
* `Modules/posixmodule.c:os_setgroups`: check if `grouplist` is allocated, raise `MemoryError` otherwise
* `Modules/sha1module.c:newSHA1object`: check `sha` value for NULL
* `Modules/zlibmodule.c:ZlibDecompressor__new__`: check `self` value for NULL
  • Loading branch information
chgnrdv committed May 16, 2023
commit b3e6f44212a1534d0ec05de57fefaa33fe77d9b7
5 changes: 1 addition & 4 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3252,7 +3252,6 @@ _curses_initscr_impl(PyObject *module)
/*[clinic end generated code: output=619fb68443810b7b input=514f4bce1821f6b5]*/
{
WINDOW *win;
PyCursesWindowObject *winobj;

if (initialised) {
wrefresh(stdscr);
Expand Down Expand Up @@ -3348,9 +3347,7 @@ _curses_initscr_impl(PyObject *module)
SetDictInt("LINES", LINES);
SetDictInt("COLS", COLS);

winobj = (PyCursesWindowObject *)PyCursesWindow_New(win, NULL);
screen_encoding = winobj->encoding;
return (PyObject *)winobj;
return (PyObject *)PyCursesWindow_New(win, screen_encoding);
}

/*[clinic input]
Expand Down
3 changes: 3 additions & 0 deletions Modules/_zoneinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2572,6 +2572,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);

Expand Down
1 change: 1 addition & 0 deletions Modules/errnomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions Modules/sha1module.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ static SHA1object *
newSHA1object(SHA1State *st)
{
SHA1object *sha = (SHA1object *)PyObject_GC_New(SHA1object, st->sha1_type);
if (sha == NULL) {
return NULL;
}
PyObject_GC_Track(sha);
return sha;
}
Expand Down
3 changes: 3 additions & 0 deletions Modules/zlibmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
0