diff options
| author | Donghee Na <donghee.na@python.org> | 2024-08-22 16:37:26 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-22 16:37:26 (GMT) |
| commit | 6cd67e413b9a6c5c81466c4e516bca6430d7297e (patch) | |
| tree | 45d2fb6df2aad68de6acfc560a8ce1d44d9fa9df /Python/bytecodes.c | |
| parent | e4b91b7256036b23a9cc91638106810d4a6ddc7a (diff) | |
| download | cpython-6cd67e413b9a6c5c81466c4e516bca6430d7297e.zip cpython-6cd67e413b9a6c5c81466c4e516bca6430d7297e.tar.gz cpython-6cd67e413b9a6c5c81466c4e516bca6430d7297e.tar.bz2 | |
[3.13] gh-123083: Fix a potential use-after-free in ``STORE_ATTR_WITH… (#123235)
[3.13] gh-123083: Fix a potential use-after-free in ``STORE_ATTR_WITH_HINT`` (gh-123092)
(cherry picked from commit 297f2e093ec95800ae2184330b8408c875523467)
Diffstat (limited to 'Python/bytecodes.c')
| -rw-r--r-- | Python/bytecodes.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c index cac9f67..c222fcd 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -2170,14 +2170,15 @@ dummy_func( new_version = _PyDict_NotifyEvent(tstate->interp, PyDict_EVENT_MODIFIED, dict, name, value); ep->me_value = value; } - Py_DECREF(old_value); - STAT_INC(STORE_ATTR, hit); /* Ensure dict is GC tracked if it needs to be */ if (!_PyObject_GC_IS_TRACKED(dict) && _PyObject_GC_MAY_BE_TRACKED(value)) { _PyObject_GC_TRACK(dict); } - /* PEP 509 */ - dict->ma_version_tag = new_version; + dict->ma_version_tag = new_version; // PEP 509 + // old_value should be DECREFed after GC track checking is done, if not, it could raise a segmentation fault, + // when dict only holds the strong reference to value in ep->me_value. + Py_DECREF(old_value); + STAT_INC(STORE_ATTR, hit); Py_DECREF(owner); } |
