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

Unified Diff: ui/gfx/mojo/buffer_types_traits.cc

Issue 2415443005: gfx: Fix sending an invalid GpuMemoryBufferHandle over mojo. (Closed)
Patch Set: . Created 4 years, 2 months 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 | « ui/gfx/mojo/buffer_types.mojom ('k') | ui/gfx/mojo/struct_traits_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/mojo/buffer_types_traits.cc
diff --git a/ui/gfx/mojo/buffer_types_traits.cc b/ui/gfx/mojo/buffer_types_traits.cc
index 71cef1b8fb133e8c462c72f01b4f1b084cf3d804..122d844079e0c056813829de1698a055219e8cec 100644
--- a/ui/gfx/mojo/buffer_types_traits.cc
+++ b/ui/gfx/mojo/buffer_types_traits.cc
@@ -72,6 +72,8 @@ mojo::ScopedHandle StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
DCHECK(handle.handle.auto_close || handle.handle.fd == -1);
platform_file = handle.handle.fd;
#endif
+ if (platform_file == base::kInvalidPlatformFile)
+ return mojo::ScopedHandle();
return mojo::WrapPlatformFile(platform_file);
}
@@ -94,20 +96,25 @@ bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
if (!data.ReadType(&out->type) || !data.ReadId(&out->id))
return false;
- base::PlatformFile platform_file;
- MojoResult unwrap_result = mojo::UnwrapPlatformFile(
- data.TakeSharedMemoryHandle(), &platform_file);
- if (unwrap_result != MOJO_RESULT_OK)
- return false;
+ mojo::ScopedHandle handle = data.TakeSharedMemoryHandle();
+ if (handle.is_valid()) {
+ base::PlatformFile platform_file;
+ MojoResult unwrap_result = mojo::UnwrapPlatformFile(
+ std::move(handle), &platform_file);
+ if (unwrap_result != MOJO_RESULT_OK)
+ return false;
#if defined(OS_WIN)
- out->handle =
- base::SharedMemoryHandle(platform_file, base::GetCurrentProcId());
+ out->handle =
+ base::SharedMemoryHandle(platform_file, base::GetCurrentProcId());
#elif defined(OS_MACOSX) || defined(OS_IOS)
- // TODO: Add support for mach_port on mac.
- out->handle = base::SharedMemoryHandle();
+ // TODO: Add support for mach_port on mac.
+ out->handle = base::SharedMemoryHandle();
#else
- out->handle = base::SharedMemoryHandle(platform_file, true);
+ out->handle = base::SharedMemoryHandle(platform_file, true);
#endif
+ } else {
+ out->handle = base::SharedMemoryHandle();
+ }
out->offset = data.offset();
out->stride = data.stride();
« no previous file with comments | « ui/gfx/mojo/buffer_types.mojom ('k') | ui/gfx/mojo/struct_traits_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698