mirror of
https://github.com/python/cpython.git
synced 2025-08-21 09:21:18 +00:00
Backport r60148 and r65481: sanity checks to avoid infinite loops.
This commit is contained in:
parent
1576bab042
commit
032215451b
2 changed files with 25 additions and 1 deletions
|
@ -264,15 +264,25 @@ static int nkeys = 0; /* PyThread_create_key() hands out nkeys+1 next */
|
|||
static struct key *
|
||||
find_key(int key, void *value)
|
||||
{
|
||||
struct key *p;
|
||||
struct key *p, *prev_p;
|
||||
long id = PyThread_get_thread_ident();
|
||||
|
||||
if (!keymutex)
|
||||
return NULL;
|
||||
PyThread_acquire_lock(keymutex, 1);
|
||||
prev_p = NULL;
|
||||
for (p = keyhead; p != NULL; p = p->next) {
|
||||
if (p->id == id && p->key == key)
|
||||
goto Done;
|
||||
/* Sanity check. These states should never happen but if
|
||||
* they do we must abort. Otherwise we'll end up spinning in
|
||||
* in a tight loop with the lock held. A similar check is done
|
||||
* in pystate.c tstate_delete_common(). */
|
||||
if (p == prev_p)
|
||||
Py_FatalError("tls find_key: small circular list(!)");
|
||||
prev_p = p;
|
||||
if (p->next == keyhead)
|
||||
Py_FatalError("tls find_key: circular list(!)");
|
||||
}
|
||||
if (value == NULL) {
|
||||
assert(p == NULL);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue