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

Unified Diff: mojo/public/c/bindings/lib/struct.c

Issue 1654373002: C types and utilities to validate and access struct and message headers (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: review feedback, for trybots Created 4 years, 11 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 | « mojo/public/c/bindings/lib/message.c ('k') | mojo/public/c/bindings/message.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/c/bindings/lib/struct.c
diff --git a/mojo/public/c/bindings/lib/struct.c b/mojo/public/c/bindings/lib/struct.c
new file mode 100644
index 0000000000000000000000000000000000000000..df791c177ae0aeda72bc27fff3e58898adb18e79
--- /dev/null
+++ b/mojo/public/c/bindings/lib/struct.c
@@ -0,0 +1,25 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/c/bindings/struct.h"
+
+#include <stdint.h>
+
+_Static_assert(sizeof(mojo_struct_header_t) == 8u,
+ "mojo_struct_header_t should be 8 bytes");
+
+bool mojo_validate_struct_header(const void* data, size_t size) {
+ if (size < sizeof(mojo_struct_header_t) || size > UINT32_MAX) {
+ return false;
+ }
+
+ const mojo_struct_header_t* header = (const mojo_struct_header_t*)data;
+
+ if (header->num_bytes < sizeof(mojo_struct_header_t) ||
+ header->num_bytes > size) {
+ return false;
+ }
+
+ return true;
+}
« no previous file with comments | « mojo/public/c/bindings/lib/message.c ('k') | mojo/public/c/bindings/message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698