Skip to content

bpo-37316: mmap.mmap() passes the wrong variable to PySys_Audit() #14152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/test/audit-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ def trace(frame, event, *args):
assertSequenceEqual(["call"] * 4, traced)


def test_mmap():
import mmap
with TestHook() as hook:
mmap.mmap(-1, 8)
assertEqual(hook.seen[0][1][:2], (-1, 8))


if __name__ == "__main__":
from test.libregrtest.setup import suppress_msvcrt_asserts
suppress_msvcrt_asserts(False)
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def test_open(self):
def test_cantrace(self):
self.do_test("test_cantrace")

def test_mmap(self):
self.do_test("test_mmap")


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the :c:func:`PySys_Audit` call in :class:`mmap.mmap`.
2 changes: 1 addition & 1 deletion Modules/mmapmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
}

if (PySys_Audit("mmap.__new__", "ini" _Py_PARSE_OFF_T,
fileno, map_size, access, offset) < 0) {
fd, map_size, access, offset) < 0) {
return NULL;
}

Expand Down
1 change: 1 addition & 0 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ PySys_Audit(const char *event, const char *argFormat, ...)
va_list args;
va_start(args, argFormat);
eventArgs = Py_VaBuildValue(argFormat, args);
va_end(args);
if (eventArgs && !PyTuple_Check(eventArgs)) {
PyObject *argTuple = PyTuple_Pack(1, eventArgs);
Py_DECREF(eventArgs);
Expand Down