]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-151773: Fix NULL dereference in `PyContextVar_Set` (GH-151836) (#152011)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 23 Jun 2026 14:39:29 +0000 (16:39 +0200)
committerGitHub <noreply@github.com>
Tue, 23 Jun 2026 14:39:29 +0000 (14:39 +0000)
gh-151773: Fix NULL dereference in `PyContextVar_Set` (GH-151836)
(cherry picked from commit d35b1719a58c8682a22ef698e070e97661af8d14)

Co-authored-by: dev <b.chouksey27@gmail.com>
Misc/NEWS.d/next/Core_and_Builtins/2026-06-21-16-00-00.gh-issue-151773.mN4kRt.rst [new file with mode: 0644]
Python/context.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-21-16-00-00.gh-issue-151773.mN4kRt.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-21-16-00-00.gh-issue-151773.mN4kRt.rst
new file mode 100644 (file)
index 0000000..b4193c5
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a crash in :func:`contextvars.ContextVar.set` when memory allocation
+fails.
index bc8b45cf6f1d5b00ef829cd343c8db87b970c46f..5c48ef7a138b12544a587d8da6b35298505b2f70 100644 (file)
@@ -278,6 +278,9 @@ PyContextVar_Set(PyObject *ovar, PyObject *val)
     Py_XINCREF(old_val);
     PyContextToken *tok = token_new(ctx, var, old_val);
     Py_XDECREF(old_val);
+    if (tok == NULL) {
+        return NULL;
+    }
 
     if (contextvar_set(var, val)) {
         Py_DECREF(tok);