[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser] 224/311: Bug 1757805 - Add additional assertions around shmem size, r=ipc-reviewers, handyman a=dmeehan



This is an automated email from the git hooks/post-receive script.

pierov pushed a commit to branch geckoview-99.0.1-11.0-1
in repository tor-browser.

commit 13aa5f97acab39986f7000f8af461b35238576ee
Author: Nika Layzell <nika@xxxxxxxxxxxxxxx>
AuthorDate: Mon Mar 21 14:37:50 2022 +0000

    Bug 1757805 - Add additional assertions around shmem size, r=ipc-reviewers,handyman a=dmeehan
    
    Differential Revision: https://phabricator.services.mozilla.com/D140097
---
 ipc/glue/Shmem.cpp | 10 ++++++++++
 ipc/glue/Shmem.h   |  7 -------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/ipc/glue/Shmem.cpp b/ipc/glue/Shmem.cpp
index 74470ec3c883e..642ddbbcf0341 100644
--- a/ipc/glue/Shmem.cpp
+++ b/ipc/glue/Shmem.cpp
@@ -243,6 +243,9 @@ Shmem::Shmem(PrivateIPDLCaller, SharedMemory* aSegment, id_t aId)
   mSize = static_cast<size_t>(header->mSize);
 
   size_t pageSize = SharedMemory::SystemPageSize();
+  MOZ_ASSERT(mSegment->Size() - (2 * pageSize) >= mSize,
+             "illegal size in shared memory segment");
+
   // transition into the "mapped" state by protecting the front and
   // back sentinels (which guard against buffer under/overflows)
   mSegment->Protect(frontSentinel, pageSize, RightsNone);
@@ -375,6 +378,13 @@ void Shmem::Dealloc(PrivateIPDLCaller, SharedMemory* aSegment) {
 
 #else  // !defined(DEBUG)
 
+Shmem::Shmem(PrivateIPDLCaller, SharedMemory* aSegment, id_t aId)
+    : mSegment(aSegment), mData(aSegment->memory()), mSize(0), mId(aId) {
+  mSize = static_cast<size_t>(*PtrToSize(mSegment));
+  MOZ_RELEASE_ASSERT(mSegment->Size() - sizeof(uint32_t) >= mSize,
+                     "illegal size in shared memory segment");
+}
+
 // static
 already_AddRefed<Shmem::SharedMemory> Shmem::Alloc(PrivateIPDLCaller,
                                                    size_t aNBytes,
diff --git a/ipc/glue/Shmem.h b/ipc/glue/Shmem.h
index dec39f3cd6499..5ea73c7195569 100644
--- a/ipc/glue/Shmem.h
+++ b/ipc/glue/Shmem.h
@@ -85,14 +85,7 @@ class Shmem final {
 
   Shmem(const Shmem& aOther) = default;
 
-#if !defined(DEBUG)
-  Shmem(PrivateIPDLCaller, SharedMemory* aSegment, id_t aId)
-      : mSegment(aSegment), mData(aSegment->memory()), mSize(0), mId(aId) {
-    mSize = static_cast<size_t>(*PtrToSize(mSegment));
-  }
-#else
   Shmem(PrivateIPDLCaller, SharedMemory* aSegment, id_t aId);
-#endif
 
   ~Shmem() {
     // Shmem only holds a "weak ref" to the actual segment, which is

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits