summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2018-02-25 09:48:02 +0100
committerGitHub <noreply@github.com>2018-02-25 09:48:02 +0100
commit6e8f395001b026daea047cf225dcca5a973ae824 (patch)
tree3dfb07c9eef71348d51b14dc3a71996a29f7f4ee /Modules
parent8d4d17399fb82801eaaca5beeb97a19908b40222 (diff)
downloadcpython-git-6e8f395001b026daea047cf225dcca5a973ae824.tar.gz
bpo-25404: SSLContext.load_dh_params() non-ASCII path (GH-3459)
SSLContext.load_dh_params() now supports non-ASCII path. Signed-off-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ssl.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index f70af26673..ec61a700b0 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -2983,13 +2983,25 @@ load_dh_params(PySSLContext *self, PyObject *filepath)
{
BIO *bio;
DH *dh;
- char *path = PyBytes_AsString(filepath);
- if (!path) {
- return NULL;
+ PyObject *filepath_bytes = NULL;
+
+ if (PyString_Check(filepath)) {
+ Py_INCREF(filepath);
+ filepath_bytes = filepath;
+ } else {
+ PyObject *u = PyUnicode_FromObject(filepath);
+ if (!u)
+ return NULL;
+ filepath_bytes = PyUnicode_AsEncodedString(
+ u, Py_FileSystemDefaultEncoding, NULL);
+ Py_DECREF(u);
+ if (!filepath_bytes)
+ return NULL;
}
- bio = BIO_new_file(path, "r");
+ bio = BIO_new_file(PyBytes_AS_STRING(filepath_bytes), "r");
if (bio == NULL) {
+ Py_DECREF(filepath_bytes);
ERR_clear_error();
PyErr_SetFromErrnoWithFilenameObject(PyExc_IOError, filepath);
return NULL;
@@ -2998,6 +3010,7 @@ load_dh_params(PySSLContext *self, PyObject *filepath)
PySSL_BEGIN_ALLOW_THREADS
dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
BIO_free(bio);
+ Py_DECREF(filepath_bytes);
PySSL_END_ALLOW_THREADS
if (dh == NULL) {
if (errno != 0) {