From c6d49c47a0855f6d1283771b56e1f2a7ab2599b0 Mon Sep 17 00:00:00 2001 From: Sim Sun Date: Fri, 4 Sep 2020 17:59:14 -0700 Subject: linux: Fix leak when the offset of memory_mapped_file is greater than 0 Breakpad should only map the file content after the offset instead of the whole file. Mapping the whole file while only unmap 'file_len - offset' would leak 'offset' bytes of mapping in virtual memory. Change-Id: I10be4f929d969703a6a02c1f709d2a4ca86a6e9e Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/2393468 Reviewed-by: Mike Frysinger --- src/common/linux/memory_mapped_file.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/common/linux/memory_mapped_file.cc b/src/common/linux/memory_mapped_file.cc index 4e938269..99362945 100644 --- a/src/common/linux/memory_mapped_file.cc +++ b/src/common/linux/memory_mapped_file.cc @@ -87,13 +87,14 @@ bool MemoryMappedFile::Map(const char* path, size_t offset) { return true; } - void* data = sys_mmap(NULL, file_len, PROT_READ, MAP_PRIVATE, fd, offset); + size_t content_len = file_len - offset; + void* data = sys_mmap(NULL, content_len, PROT_READ, MAP_PRIVATE, fd, offset); sys_close(fd); if (data == MAP_FAILED) { return false; } - content_.Set(data, file_len - offset); + content_.Set(data, content_len); return true; } -- cgit v1.2.1