summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend.aasland@protonmail.com>2023-06-11 09:56:32 (GMT)
committerGitHub <noreply@github.com>2023-06-11 09:56:32 (GMT)
commit01f4230460454d4a849a5ba93320142c1a0c93a8 (patch)
tree3119b5c2d9d83c9556c596d5862440f0502c747c /Modules
parentcc879481e2ac29742ce191f4c6ed4bd85e5e11ba (diff)
downloadcpython-01f4230460454d4a849a5ba93320142c1a0c93a8.zip
cpython-01f4230460454d4a849a5ba93320142c1a0c93a8.tar.gz
cpython-01f4230460454d4a849a5ba93320142c1a0c93a8.tar.bz2
gh-105375: Harden _ssl initialisation (#105599)
Add proper error handling to prevent reference leaks and overwritten exceptions.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ssl.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index de90a4a..7a13821 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -6001,15 +6001,21 @@ sslmodule_init_errorcodes(PyObject *module)
errcode = error_codes;
while (errcode->mnemonic != NULL) {
- PyObject *mnemo, *key;
- mnemo = PyUnicode_FromString(errcode->mnemonic);
- key = Py_BuildValue("ii", errcode->library, errcode->reason);
- if (mnemo == NULL || key == NULL)
+ PyObject *mnemo = PyUnicode_FromString(errcode->mnemonic);
+ if (mnemo == NULL) {
return -1;
- if (PyDict_SetItem(state->err_codes_to_names, key, mnemo))
+ }
+ PyObject *key = Py_BuildValue("ii", errcode->library, errcode->reason);
+ if (key == NULL) {
+ Py_DECREF(mnemo);
return -1;
+ }
+ int rc = PyDict_SetItem(state->err_codes_to_names, key, mnemo);
Py_DECREF(key);
Py_DECREF(mnemo);
+ if (rc < 0) {
+ return -1;
+ }
errcode++;
}