[Python-checkins] cpython (merge 3.5 -> 3.6): Issue #29190: Fixed possible errors in comparing strings in the pickle module.

serhiy.storchaka python-checkins at python.org
Mon Jan 9 03:10:39 EST 2017


https://hg.python.org/cpython/rev/9fcff936f61f
changeset:   106058:9fcff936f61f
branch:      3.6
parent:      106055:e90efd9f203e
parent:      106057:337461574c90
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Mon Jan 09 10:09:43 2017 +0200
summary:
  Issue #29190: Fixed possible errors in comparing strings in the pickle module.

files:
  Modules/_pickle.c |  18 ++++++------------
  1 files changed, 6 insertions(+), 12 deletions(-)


diff --git a/Modules/_pickle.c b/Modules/_pickle.c
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -1560,9 +1560,9 @@
 }
 
 static PyObject *
-get_dotted_path(PyObject *obj, PyObject *name) {
+get_dotted_path(PyObject *obj, PyObject *name)
+{
     _Py_static_string(PyId_dot, ".");
-    _Py_static_string(PyId_locals, "<locals>");
     PyObject *dotted_path;
     Py_ssize_t i, n;
 
@@ -1573,12 +1573,7 @@
     assert(n >= 1);
     for (i = 0; i < n; i++) {
         PyObject *subpath = PyList_GET_ITEM(dotted_path, i);
-        PyObject *result = PyUnicode_RichCompare(
-            subpath, _PyUnicode_FromId(&PyId_locals), Py_EQ);
-        int is_equal = (result == Py_True);
-        assert(PyBool_Check(result));
-        Py_DECREF(result);
-        if (is_equal) {
+        if (_PyUnicode_EqualToASCIIString(subpath, "<locals>")) {
             if (obj == NULL)
                 PyErr_Format(PyExc_AttributeError,
                              "Can't pickle local object %R", name);
@@ -3552,12 +3547,11 @@
         }
         else if (PyUnicode_Check(name)) {
             _Py_IDENTIFIER(__newobj_ex__);
-            use_newobj_ex = PyUnicode_Compare(
-                    name, _PyUnicode_FromId(&PyId___newobj_ex__)) == 0;
+            use_newobj_ex = _PyUnicode_EqualToASCIIId(
+                    name, &PyId___newobj_ex__);
             if (!use_newobj_ex) {
                 _Py_IDENTIFIER(__newobj__);
-                use_newobj = PyUnicode_Compare(
-                        name, _PyUnicode_FromId(&PyId___newobj__)) == 0;
+                use_newobj = _PyUnicode_EqualToASCIIId(name, &PyId___newobj__);
             }
         }
         Py_XDECREF(name);

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list