[Python-checkins] bpo-43636: Validate the version tag in _PyType_Lookup (GH-25032)

pablogsal webhook-mailer at python.org
Fri Mar 26 23:51:54 EDT 2021


https://github.com/python/cpython/commit/11b85abbae8aaa8410b19f358abd7b401881bb1c
commit: 11b85abbae8aaa8410b19f358abd7b401881bb1c
branch: master
author: Pablo Galindo <Pablogsal at gmail.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2021-03-27T03:51:46Z
summary:

bpo-43636: Validate the version tag in _PyType_Lookup (GH-25032)

files:
M Objects/typeobject.c

diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index d1bbbe77ee1b9..8dafbbf297733 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -424,7 +424,7 @@ assign_version_tag(struct type_cache *cache, PyTypeObject *type)
     if (type->tp_version_tag == 0) {
         // Wrap-around or just starting Python - clear the whole cache
         type_cache_clear(cache, 1);
-        return 1;
+        return 0;
     }
 
     bases = type->tp_bases;
@@ -3361,6 +3361,7 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
 #if MCACHE_STATS
         cache->hits++;
 #endif
+        assert(_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG));
         return entry->value;
     }
 
@@ -3398,6 +3399,7 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
             cache->misses++;
         }
 #endif
+        assert(_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG));
         Py_SETREF(entry->name, Py_NewRef(name));
     }
     return res;



More information about the Python-checkins mailing list