Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06a4fcb

Browse files
authored
bpo-29438: Fixed use-after-free in key sharing dict (python#40)
1 parent cabd1c7 commit 06a4fcb

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Misc/NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Release date: XXXX-XX-XX
1010
Core and Builtins
1111
-----------------
1212

13+
- bpo-29438: Fixed use-after-free problem in key sharing dict.
14+
1315
- Issue #29319: Prevent RunMainFromImporter overwriting sys.path[0].
1416

1517
- Issue #29337: Fixed possible BytesWarning when compare the code objects.

Objects/dictobject.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -3893,20 +3893,18 @@ _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr,
38933893
}
38943894
if (value == NULL) {
38953895
res = PyDict_DelItem(dict, key);
3896-
if (cached != ((PyDictObject *)dict)->ma_keys) {
3897-
CACHED_KEYS(tp) = NULL;
3898-
DK_DECREF(cached);
3899-
}
39003896
}
39013897
else {
3902-
int was_shared = cached == ((PyDictObject *)dict)->ma_keys;
3898+
int was_shared = (cached == ((PyDictObject *)dict)->ma_keys);
39033899
res = PyDict_SetItem(dict, key, value);
39043900
/* PyDict_SetItem() may call dictresize() and convert split table
39053901
* into combined table. In such case, convert it to split
39063902
* table again and update type's shared key only when this is
39073903
* the only dict sharing key with the type.
39083904
*/
3909-
if (was_shared && cached != ((PyDictObject *)dict)->ma_keys) {
3905+
if (was_shared &&
3906+
(cached = CACHED_KEYS(tp)) != NULL &&
3907+
cached != ((PyDictObject *)dict)->ma_keys) {
39103908
if (cached->dk_refcnt == 1) {
39113909
CACHED_KEYS(tp) = make_keys_shared(dict);
39123910
} else {

0 commit comments

Comments
 (0)