summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend.aasland@protonmail.com>2023-06-09 20:36:53 (GMT)
committerGitHub <noreply@github.com>2023-06-09 20:36:53 (GMT)
commite0087df65df485478401aec321b22e2f92407cd3 (patch)
treeec4f14f42628fbb8d263ba38160745e8dddcabaf /Modules
parent04b76ece7f92bd7e46ca2f3b46e7a42cfd75fa05 (diff)
downloadcpython-e0087df65df485478401aec321b22e2f92407cd3.zip
cpython-e0087df65df485478401aec321b22e2f92407cd3.tar.gz
cpython-e0087df65df485478401aec321b22e2f92407cd3.tar.bz2
[3.12] gh-105375: Improve errnomodule error handling (#105590) (#105596)
(cherry picked from commit eede1d2f48b4fe7f7918952d9ebeb744b58668c1) Bail immediately if an exception is set, to prevent exceptions from being overwritten.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/errnomodule.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c
index fddde96..301ad83 100644
--- a/Modules/errnomodule.c
+++ b/Modules/errnomodule.c
@@ -81,9 +81,12 @@ end:
static int
errno_exec(PyObject *module)
{
- PyObject *module_dict = PyModule_GetDict(module);
+ PyObject *module_dict = PyModule_GetDict(module); // Borrowed ref.
+ if (module_dict == NULL) {
+ return -1;
+ }
PyObject *error_dict = PyDict_New();
- if (!module_dict || !error_dict) {
+ if (error_dict == NULL) {
return -1;
}
if (PyDict_SetItemString(module_dict, "errorcode", error_dict) < 0) {