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

Unified Diff: mojo/public/cpp/system/platform_handle.cc

Issue 2583583002: Mojo: Fix wrapping of invalid SharedMemoryHandles. (Closed)
Patch Set: . Created 4 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 | « components/discardable_memory/public/interfaces/discardable_shared_memory_manager.mojom ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/system/platform_handle.cc
diff --git a/mojo/public/cpp/system/platform_handle.cc b/mojo/public/cpp/system/platform_handle.cc
index 51dfc0ec898bf5fb05db34d4744d16e7463c4598..42e4abac832c703db4f52a0e0fc4e13ba3256684 100644
--- a/mojo/public/cpp/system/platform_handle.cc
+++ b/mojo/public/cpp/system/platform_handle.cc
@@ -66,6 +66,13 @@ ScopedSharedBufferHandle WrapSharedMemoryHandle(
const base::SharedMemoryHandle& memory_handle,
size_t size,
bool read_only) {
+#if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS))
+ if (memory_handle.fd == base::kInvalidPlatformFile)
+ return ScopedSharedBufferHandle();
+#else
+ if (!memory_handle.IsValid())
+ return ScopedSharedBufferHandle();
+#endif
MojoPlatformHandle platform_handle;
platform_handle.struct_size = sizeof(MojoPlatformHandle);
platform_handle.type = kPlatformSharedBufferHandleType;
@@ -96,6 +103,8 @@ MojoResult UnwrapSharedMemoryHandle(ScopedSharedBufferHandle handle,
base::SharedMemoryHandle* memory_handle,
size_t* size,
bool* read_only) {
+ if (!handle.is_valid())
+ return MOJO_RESULT_INVALID_ARGUMENT;
MojoPlatformHandle platform_handle;
platform_handle.struct_size = sizeof(MojoPlatformHandle);
« no previous file with comments | « components/discardable_memory/public/interfaces/discardable_shared_memory_manager.mojom ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698