mirror of
https://github.com/python/cpython.git
synced 2025-08-25 11:15:02 +00:00
bpo-41180: Replace marshal code.__new__ audit event with marshal.load[s] and marshal.dumps (GH-26970)
This commit is contained in:
parent
2df13e1211
commit
a5764d3d96
5 changed files with 75 additions and 10 deletions
|
@ -596,14 +596,18 @@ PyMarshal_WriteObjectToFile(PyObject *x, FILE *fp, int version)
|
|||
{
|
||||
char buf[BUFSIZ];
|
||||
WFILE wf;
|
||||
if (PySys_Audit("marshal.dumps", "Oi", x, version) < 0) {
|
||||
return; /* caller must check PyErr_Occurred() */
|
||||
}
|
||||
memset(&wf, 0, sizeof(wf));
|
||||
wf.fp = fp;
|
||||
wf.ptr = wf.buf = buf;
|
||||
wf.end = wf.ptr + sizeof(buf);
|
||||
wf.error = WFERR_OK;
|
||||
wf.version = version;
|
||||
if (w_init_refs(&wf, version))
|
||||
return; /* caller mush check PyErr_Occurred() */
|
||||
if (w_init_refs(&wf, version)) {
|
||||
return; /* caller must check PyErr_Occurred() */
|
||||
}
|
||||
w_object(x, &wf);
|
||||
w_clear_refs(&wf);
|
||||
w_flush(&wf);
|
||||
|
@ -1371,12 +1375,6 @@ r_object(RFILE *p)
|
|||
if (linetable == NULL)
|
||||
goto code_error;
|
||||
|
||||
if (PySys_Audit("code.__new__", "OOOiiiiii",
|
||||
code, filename, name, argcount, posonlyargcount,
|
||||
kwonlyargcount, nlocals, stacksize, flags) < 0) {
|
||||
goto code_error;
|
||||
}
|
||||
|
||||
v = (PyObject *) PyCode_NewWithPosOnlyArgs(
|
||||
argcount, posonlyargcount, kwonlyargcount,
|
||||
nlocals, stacksize, flags,
|
||||
|
@ -1435,6 +1433,15 @@ read_object(RFILE *p)
|
|||
fprintf(stderr, "XXX readobject called with exception set\n");
|
||||
return NULL;
|
||||
}
|
||||
if (p->ptr && p->end) {
|
||||
if (PySys_Audit("marshal.loads", "y#", p->ptr, (Py_ssize_t)(p->end - p->ptr)) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
} else if (p->fp || p->readable) {
|
||||
if (PySys_Audit("marshal.load", NULL) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
v = r_object(p);
|
||||
if (v == NULL && !PyErr_Occurred())
|
||||
PyErr_SetString(PyExc_TypeError, "NULL object in marshal data for object");
|
||||
|
@ -1531,7 +1538,7 @@ PyMarshal_ReadObjectFromFile(FILE *fp)
|
|||
rf.refs = PyList_New(0);
|
||||
if (rf.refs == NULL)
|
||||
return NULL;
|
||||
result = r_object(&rf);
|
||||
result = read_object(&rf);
|
||||
Py_DECREF(rf.refs);
|
||||
if (rf.buf != NULL)
|
||||
PyMem_Free(rf.buf);
|
||||
|
@ -1552,7 +1559,7 @@ PyMarshal_ReadObjectFromString(const char *str, Py_ssize_t len)
|
|||
rf.refs = PyList_New(0);
|
||||
if (rf.refs == NULL)
|
||||
return NULL;
|
||||
result = r_object(&rf);
|
||||
result = read_object(&rf);
|
||||
Py_DECREF(rf.refs);
|
||||
if (rf.buf != NULL)
|
||||
PyMem_Free(rf.buf);
|
||||
|
@ -1564,6 +1571,9 @@ PyMarshal_WriteObjectToString(PyObject *x, int version)
|
|||
{
|
||||
WFILE wf;
|
||||
|
||||
if (PySys_Audit("marshal.dumps", "Oi", x, version) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
memset(&wf, 0, sizeof(wf));
|
||||
wf.str = PyBytes_FromStringAndSize((char *)NULL, 50);
|
||||
if (wf.str == NULL)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue