An interpreted, interactive, object-oriented programming language
CentOS Sources
2017-08-01 71084d584ff953f5463757ec6536406320560b4d
commit | author | age
f63228 1
CS 2 # HG changeset patch
3 # User Benjamin Peterson <benjamin@python.org>
4 # Date 1409232801 14400
5 # Node ID 97081a80f487841d81aeed55d398a1dba1faca00
6 # Parent  3ae399c6ecf685086ebf07e17717955f21e14cb8
7 fix load_verify_locations on unicode paths (closes #22244)
8
9 diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
10 --- a/Lib/test/test_ssl.py
11 +++ b/Lib/test/test_ssl.py
12 @@ -850,11 +850,14 @@ class ContextTests(unittest.TestCase):
13          ctx.load_verify_locations(cafile=CERTFILE, capath=None)
14          ctx.load_verify_locations(BYTES_CERTFILE)
15          ctx.load_verify_locations(cafile=BYTES_CERTFILE, capath=None)
16 +        ctx.load_verify_locations(cafile=BYTES_CERTFILE.decode('utf-8'))
17          self.assertRaises(TypeError, ctx.load_verify_locations)
18          self.assertRaises(TypeError, ctx.load_verify_locations, None, None, None)
19          with self.assertRaises(IOError) as cm:
20              ctx.load_verify_locations(WRONGCERT)
21          self.assertEqual(cm.exception.errno, errno.ENOENT)
22 +        with self.assertRaises(IOError):
23 +            ctx.load_verify_locations(u'')
24          with self.assertRaisesRegexp(ssl.SSLError, "PEM lib"):
25              ctx.load_verify_locations(BADCERT)
26          ctx.load_verify_locations(CERTFILE, CAPATH)
27 diff --git a/Modules/_ssl.c b/Modules/_ssl.c
28 --- a/Modules/_ssl.c
29 +++ b/Modules/_ssl.c
30 @@ -2628,17 +2628,33 @@ load_verify_locations(PySSLContext *self
31      }
32  
33      if (cafile) {
34 -        cafile_bytes = PyString_AsEncodedObject(
35 -            cafile, Py_FileSystemDefaultEncoding, "strict");
36 -        if (!cafile_bytes) {
37 -            goto error;
38 +        if (PyString_Check(cafile)) {
39 +            Py_INCREF(cafile);
40 +            cafile_bytes = cafile;
41 +        } else {
42 +            PyObject *u = PyUnicode_FromObject(cafile);
43 +            if (!u)
44 +                goto error;
45 +            cafile_bytes = PyUnicode_AsEncodedString(
46 +                u, Py_FileSystemDefaultEncoding, NULL);
47 +            Py_DECREF(u);
48 +            if (!cafile_bytes)
49 +                goto error;
50          }
51      }
52      if (capath) {
53 -        capath_bytes = PyString_AsEncodedObject(
54 -            capath, Py_FileSystemDefaultEncoding, "strict");
55 -        if (!capath_bytes) {
56 -            goto error;
57 +        if (PyString_Check(capath)) {
58 +            Py_INCREF(capath);
59 +            capath_bytes = capath;
60 +        } else {
61 +            PyObject *u = PyUnicode_FromObject(capath);
62 +            if (!u)
63 +                goto error;
64 +            capath_bytes = PyUnicode_AsEncodedString(
65 +                u, Py_FileSystemDefaultEncoding, NULL);
66 +            Py_DECREF(u);
67 +            if (!capath_bytes)
68 +                goto error;
69          }
70      }
71  
72