Skip to content

Commit 11b85ab

Browse files
authored
bpo-43636: Validate the version tag in _PyType_Lookup (GH-25032)
1 parent 027b669 commit 11b85ab

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Objects/typeobject.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ assign_version_tag(struct type_cache *cache, PyTypeObject *type)
424424
if (type->tp_version_tag == 0) {
425425
// Wrap-around or just starting Python - clear the whole cache
426426
type_cache_clear(cache, 1);
427-
return 1;
427+
return 0;
428428
}
429429

430430
bases = type->tp_bases;
@@ -3361,6 +3361,7 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
33613361
#if MCACHE_STATS
33623362
cache->hits++;
33633363
#endif
3364+
assert(_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG));
33643365
return entry->value;
33653366
}
33663367

@@ -3398,6 +3399,7 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
33983399
cache->misses++;
33993400
}
34003401
#endif
3402+
assert(_PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG));
34013403
Py_SETREF(entry->name, Py_NewRef(name));
34023404
}
34033405
return res;

0 commit comments

Comments
 (0)