Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Unified Diff: util/mach/mach_message_server.cc

Issue 779633004: MachMessageServer: scribble over memory allocations in debug mode (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/mach/exc_client_variants_test.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/mach/mach_message_server.cc
diff --git a/util/mach/mach_message_server.cc b/util/mach/mach_message_server.cc
index c29680a61bd97b5e2f206ebe195ef240f9abc433..fea0b5d477644df29fc69374016a06fb9a6b5825 100644
--- a/util/mach/mach_message_server.cc
+++ b/util/mach/mach_message_server.cc
@@ -14,6 +14,8 @@
#include "util/mach/mach_message_server.h"
+#include <string.h>
+
#include <limits>
#include "base/logging.h"
@@ -48,27 +50,32 @@ class MachMessageBuffer {
// This test uses == instead of > so that a large reallocation to receive a
// large message doesn’t cause permanent memory bloat for the duration of
// a MachMessageServer::Run() loop.
- if (size == vm_.size()) {
- return KERN_SUCCESS;
- }
+ if (size != vm_.size()) {
+ // reset() first, so that two allocations don’t exist simultaneously.
+ vm_.reset();
+
+ if (size) {
+ vm_address_t address;
+ kern_return_t kr =
+ vm_allocate(mach_task_self(),
+ &address,
+ size,
+ VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_MACH_MSG));
+ if (kr != KERN_SUCCESS) {
+ return kr;
+ }
- // reset() first, so that two allocations don’t exist simultaneously.
- vm_.reset();
-
- if (size) {
- vm_address_t address;
- kern_return_t kr =
- vm_allocate(mach_task_self(),
- &address,
- size,
- VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_MACH_MSG));
- if (kr != KERN_SUCCESS) {
- return kr;
+ vm_.reset(address, size);
}
-
- vm_.reset(address, size);
}
+#if !defined(NDEBUG)
+ // Regardless of whether the allocation was changed, scribble over the
+ // memory to make sure that nothing relies on zero-initialization or stale
+ // contents.
+ memset(Header(), 0x66, size);
+#endif
+
return KERN_SUCCESS;
}
« no previous file with comments | « util/mach/exc_client_variants_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698