Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 32 additions & 10 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#define OPENSSL_NO_DEPRECATED 1

#define PY_SSIZE_T_CLEAN
#define NEEDS_PY_IDENTIFIER

#include "Python.h"

Expand Down Expand Up @@ -447,10 +446,6 @@ fill_and_set_sslerror(_sslmodulestate *state,
PyObject *err_value = NULL, *reason_obj = NULL, *lib_obj = NULL;
PyObject *verify_obj = NULL, *verify_code_obj = NULL;
PyObject *init_value, *msg, *key;
_Py_IDENTIFIER(reason);
_Py_IDENTIFIER(library);
_Py_IDENTIFIER(verify_message);
_Py_IDENTIFIER(verify_code);

if (errcode != 0) {
int lib, reason;
Expand Down Expand Up @@ -544,20 +539,20 @@ fill_and_set_sslerror(_sslmodulestate *state,

if (reason_obj == NULL)
reason_obj = Py_None;
if (_PyObject_SetAttrId(err_value, &PyId_reason, reason_obj))
if (PyObject_SetAttr(err_value, state->str_reason, reason_obj))
goto fail;

if (lib_obj == NULL)
lib_obj = Py_None;
if (_PyObject_SetAttrId(err_value, &PyId_library, lib_obj))
if (PyObject_SetAttr(err_value, state->str_library, lib_obj))
goto fail;

if ((sslsock != NULL) && (type == state->PySSLCertVerificationErrorObject)) {
/* Only set verify code / message for SSLCertVerificationError */
if (_PyObject_SetAttrId(err_value, &PyId_verify_code,
if (PyObject_SetAttr(err_value, state->str_verify_code,
verify_code_obj))
goto fail;
if (_PyObject_SetAttrId(err_value, &PyId_verify_message, verify_obj))
if (PyObject_SetAttr(err_value, state->str_verify_message, verify_obj))
goto fail;
}

Expand Down Expand Up @@ -6158,13 +6153,37 @@ sslmodule_init_types(PyObject *module)
return 0;
}

static int
sslmodule_init_strings(PyObject *module)
{
_sslmodulestate *state = get_ssl_state(module);
state->str_library = PyUnicode_InternFromString("library");
if (state->str_library == NULL) {
return -1;
}
state->str_reason = PyUnicode_InternFromString("reason");
if (state->str_reason == NULL) {
return -1;
}
state->str_verify_message = PyUnicode_InternFromString("verify_message");
if (state->str_verify_message == NULL) {
return -1;
}
state->str_verify_code = PyUnicode_InternFromString("verify_code");
if (state->str_verify_code == NULL) {
return -1;
}
return 0;
}

static PyModuleDef_Slot sslmodule_slots[] = {
{Py_mod_exec, sslmodule_init_types},
{Py_mod_exec, sslmodule_init_exceptions},
{Py_mod_exec, sslmodule_init_socketapi},
{Py_mod_exec, sslmodule_init_errorcodes},
{Py_mod_exec, sslmodule_init_constants},
{Py_mod_exec, sslmodule_init_versioninfo},
{Py_mod_exec, sslmodule_init_strings},
{0, NULL}
};

Expand Down Expand Up @@ -6214,7 +6233,10 @@ sslmodule_clear(PyObject *m)
Py_CLEAR(state->err_names_to_codes);
Py_CLEAR(state->lib_codes_to_names);
Py_CLEAR(state->Sock_Type);

Py_CLEAR(state->str_library);
Py_CLEAR(state->str_reason);
Py_CLEAR(state->str_verify_code);
Py_CLEAR(state->str_verify_message);
return 0;
}

Expand Down
5 changes: 5 additions & 0 deletions Modules/_ssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ typedef struct {
PyObject *lib_codes_to_names;
/* socket type from module CAPI */
PyTypeObject *Sock_Type;
/* Interned strings */
PyObject *str_library;
PyObject *str_reason;
PyObject *str_verify_code;
PyObject *str_verify_message;
} _sslmodulestate;

static struct PyModuleDef _sslmodule_def;
Expand Down