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