diff options
author | Thomas Perl <m@thp.io> | 2019-04-02 09:30:10 (GMT) |
---|---|---|
committer | Inada Naoki <songofacandy@gmail.com> | 2019-04-02 09:30:10 (GMT) |
commit | b8311cf5e5d72f8a8aa688b7da1760d6a74a4d72 (patch) | |
tree | 8b27ad7389e9fb15f38f8b96be1f3f7423f6a8b2 /Objects/dictobject.c | |
parent | 04694a306b8f4ab54ef5fc4ba673c26fa53b0ac1 (diff) | |
download | cpython-b8311cf5e5d72f8a8aa688b7da1760d6a74a4d72.zip cpython-b8311cf5e5d72f8a8aa688b7da1760d6a74a4d72.tar.gz cpython-b8311cf5e5d72f8a8aa688b7da1760d6a74a4d72.tar.bz2 |
bpo-36473: add maximum iteration check for dict .values() and .items() (GH-12619)
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 7ea979c..bba27dd 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -3630,6 +3630,12 @@ dictiter_iternextvalue(dictiterobject *di) goto fail; value = entry_ptr->me_value; } + // We found an element, but did not expect it + if (di->len == 0) { + PyErr_SetString(PyExc_RuntimeError, + "dictionary keys changed during iteration"); + goto fail; + } di->di_pos = i+1; di->len--; Py_INCREF(value); @@ -3713,6 +3719,12 @@ dictiter_iternextitem(dictiterobject *di) key = entry_ptr->me_key; value = entry_ptr->me_value; } + // We found an element, but did not expect it + if (di->len == 0) { + PyErr_SetString(PyExc_RuntimeError, + "dictionary keys changed during iteration"); + goto fail; + } di->di_pos = i+1; di->len--; Py_INCREF(key); |