summaryrefslogtreecommitdiffstats
path: root/Python/marshal.c
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2021-06-30 17:52:25 (GMT)
committerGitHub <noreply@github.com>2021-06-30 17:52:25 (GMT)
commita5764d3d96341441d3f70fb5c96a82610a3f4842 (patch)
tree816851d3b7e7b1f8bead09664cd6b8f4ffee03f3 /Python/marshal.c
parent2df13e1211cf420bf6557df02e694bf1653a0ebe (diff)
downloadcpython-a5764d3d96341441d3f70fb5c96a82610a3f4842.zip
cpython-a5764d3d96341441d3f70fb5c96a82610a3f4842.tar.gz
cpython-a5764d3d96341441d3f70fb5c96a82610a3f4842.tar.bz2
bpo-41180: Replace marshal code.__new__ audit event with marshal.load[s] and marshal.dumps (GH-26970)
Diffstat (limited to 'Python/marshal.c')
-rw-r--r--Python/marshal.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/Python/marshal.c b/Python/marshal.c
index fa4ec9e..4125240 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -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)