Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3800e1e

Browse files
author
Victor Stinner
committed
Issue #8477: _ssl._test_decode_cert() supports str with surrogates and bytes
for the filename
1 parent 27ba638 commit 3800e1e

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ C-API
363363
Library
364364
-------
365365

366+
- Issue #8477: _ssl._test_decode_cert() supports str with surrogates and bytes
367+
for the filename
368+
366369
- Issue #8550: Add first class ``SSLContext`` objects to the ssl module.
367370

368371
- Issue #8681: Make the zlib module's error messages more informative when

Modules/_ssl.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -811,13 +811,13 @@ static PyObject *
811811
PySSL_test_decode_certificate (PyObject *mod, PyObject *args) {
812812

813813
PyObject *retval = NULL;
814-
char *filename = NULL;
814+
PyObject *filename;
815815
X509 *x=NULL;
816816
BIO *cert;
817817
int verbose = 1;
818818

819-
if (!PyArg_ParseTuple(args, "s|i:test_decode_certificate",
820-
&filename, &verbose))
819+
if (!PyArg_ParseTuple(args, "O&|i:test_decode_certificate",
820+
PyUnicode_FSConverter, &filename, &verbose))
821821
return NULL;
822822

823823
if ((cert=BIO_new(BIO_s_file())) == NULL) {
@@ -826,7 +826,7 @@ PySSL_test_decode_certificate (PyObject *mod, PyObject *args) {
826826
goto fail0;
827827
}
828828

829-
if (BIO_read_filename(cert,filename) <= 0) {
829+
if (BIO_read_filename(cert, PyBytes_AsString(filename)) <= 0) {
830830
PyErr_SetString(PySSLErrorObject,
831831
"Can't open file");
832832
goto fail0;
@@ -842,7 +842,7 @@ PySSL_test_decode_certificate (PyObject *mod, PyObject *args) {
842842
retval = _decode_certificate(x, verbose);
843843

844844
fail0:
845-
845+
Py_DECREF(filename);
846846
if (cert != NULL) BIO_free(cert);
847847
return retval;
848848
}

0 commit comments

Comments
 (0)