diff --git a/Misc/NEWS.d/next/Library/2020-10-15-07-33-50.bpo-42036.MonocleAI.rst b/Misc/NEWS.d/next/Library/2020-10-15-07-33-50.bpo-42036.MonocleAI.rst new file mode 100644 index 00000000000000..5e0d6b90afa053 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-10-15-07-33-50.bpo-42036.MonocleAI.rst @@ -0,0 +1 @@ +Fix unchecked return in Modules/posixmodule.c. The return value of a function that is potentially used to initialize a local variable is not checked. Therefore, reading the local variable may result in an undefined behavior. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 6ce0bcb9fe8ca4..84dc1496d8d500 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8490,7 +8490,12 @@ os_times_impl(PyObject *module) FILETIME create, exit, kernel, user; HANDLE hProc; hProc = GetCurrentProcess(); - GetProcessTimes(hProc, &create, &exit, &kernel, &user); + BOOL ok; + ok = GetProcessTimes(hProc, &create, &exit, &kernel, &user); + if (!ok) { + PyErr_SetFromWindowsErr(0); + return -1; + } /* The fields of a FILETIME structure are the hi and lo part of a 64-bit value expressed in 100 nanosecond units. 1e7 is one second in such units; 1e-7 the inverse. @@ -15022,7 +15027,10 @@ posixmodule_exec(PyObject *m) fd_specified("", -1); follow_symlinks_specified("", 1); dir_fd_and_follow_symlinks_invalid("chmod", DEFAULT_DIR_FD, 1); - dir_fd_converter(Py_None, &ignored); + if(!dir_fd_converter(Py_None, &ignored)) + { + return 0; + } dir_fd_unavailable(Py_None, &ignored); }