Skip to content

Commit 08286d5

Browse files
ZackerySpytzzooba
authored andcommitted
bpo-37316: mmap.mmap() passes the wrong variable to PySys_Audit() (pythonGH-14152)
Also, add a missing call to va_end() in PySys_Audit().
1 parent 08970cb commit 08286d5

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

Lib/test/audit-tests.py

+7
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ def trace(frame, event, *args):
261261
assertSequenceEqual(["call"] * 4, traced)
262262

263263

264+
def test_mmap():
265+
import mmap
266+
with TestHook() as hook:
267+
mmap.mmap(-1, 8)
268+
assertEqual(hook.seen[0][1][:2], (-1, 8))
269+
270+
264271
if __name__ == "__main__":
265272
from test.libregrtest.setup import suppress_msvcrt_asserts
266273
suppress_msvcrt_asserts(False)

Lib/test/test_audit.py

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ def test_open(self):
7474
def test_cantrace(self):
7575
self.do_test("test_cantrace")
7676

77+
def test_mmap(self):
78+
self.do_test("test_mmap")
79+
7780

7881
if __name__ == "__main__":
7982
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix the :c:func:`PySys_Audit` call in :class:`mmap.mmap`.

Modules/mmapmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
11541154
}
11551155

11561156
if (PySys_Audit("mmap.__new__", "ini" _Py_PARSE_OFF_T,
1157-
fileno, map_size, access, offset) < 0) {
1157+
fd, map_size, access, offset) < 0) {
11581158
return NULL;
11591159
}
11601160

Python/sysmodule.c

+1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ PySys_Audit(const char *event, const char *argFormat, ...)
182182
va_list args;
183183
va_start(args, argFormat);
184184
eventArgs = Py_VaBuildValue(argFormat, args);
185+
va_end(args);
185186
if (eventArgs && !PyTuple_Check(eventArgs)) {
186187
PyObject *argTuple = PyTuple_Pack(1, eventArgs);
187188
Py_DECREF(eventArgs);

0 commit comments

Comments
 (0)