Skip to content

Commit b238345

Browse files
gh-143544: Fix use-after-free in _json.raise_errmsg
1 parent 099fc4f commit b238345

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Modules/_json.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,20 +417,23 @@ raise_errmsg(const char *msg, PyObject *s, Py_ssize_t end)
417417
_Py_DECLARE_STR(json_decoder, "json.decoder");
418418

419419
PyObject *JSONDecodeError =
420-
PyImport_ImportModuleAttr(&_Py_STR(json_decoder), &_Py_ID(JSONDecodeError));
420+
PyImport_ImportModuleAttr(&_Py_STR(json_decoder),
421+
&_Py_ID(JSONDecodeError));
421422
if (JSONDecodeError == NULL) {
422423
return;
423424
}
424425

425426
PyObject *exc = PyObject_CallFunction(JSONDecodeError, "zOn", msg, s, end);
426-
if (exc != NULL) {
427+
if (exc) {
427428
PyErr_SetObject(JSONDecodeError, exc);
428429
Py_DECREF(exc);
429430
}
430431

432+
/* Move DECREF after PyErr_SetObject */
431433
Py_DECREF(JSONDecodeError);
432434
}
433435

436+
434437
static void
435438
raise_stop_iteration(Py_ssize_t idx)
436439
{

0 commit comments

Comments
 (0)