]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-143544: Fix possible use-after-free in the JSON decoder when JSONDecodeErro...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 12 Jan 2026 16:02:23 +0000 (17:02 +0100)
committerGitHub <noreply@github.com>
Mon, 12 Jan 2026 16:02:23 +0000 (16:02 +0000)
gh-143544: Fix possible use-after-free in the JSON decoder when JSONDecodeError disappears during raising it (GH-143561)
(cherry picked from commit c3157480601499565fd42a8afbdb0207328ac484)

Co-authored-by: VanshAgarwal24036 <148854295+VanshAgarwal24036@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Modules/_json.c

index cc41b9ab867a2846626d4125b7bc5e7fd2194425..afefc71bfbdd9a1b8b5ff2e2a0bfaa63ffc2c318 100644 (file)
@@ -308,11 +308,12 @@ raise_errmsg(const char *msg, PyObject *s, Py_ssize_t end)
 
     PyObject *exc;
     exc = PyObject_CallFunction(JSONDecodeError, "zOn", msg, s, end);
-    Py_DECREF(JSONDecodeError);
     if (exc) {
         PyErr_SetObject(JSONDecodeError, exc);
         Py_DECREF(exc);
     }
+
+    Py_DECREF(JSONDecodeError);
 }
 
 static void