| 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..57cb19a2b87f4969767e125bacf198d6bb09746a
|
| --- /dev/null
|
| +++ b/mojo/public/c/bindings/lib/struct.c
|
| @@ -0,0 +1,23 @@
|
| +// 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"
|
| +
|
| +_Static_assert(sizeof(mojo_struct_header_t) == 8u,
|
| + "mojo_struct_header_t should be 8 bytes");
|
| +
|
| +bool mojo_validate_struct_header(void* data, uint32_t size) {
|
| + if (size < sizeof(mojo_struct_header_t)) {
|
| + return false;
|
| + }
|
| +
|
| + mojo_struct_header_t* header = (mojo_struct_header_t*)data;
|
| +
|
| + if (header->num_bytes < sizeof(mojo_struct_header_t) ||
|
| + header->num_bytes > size) {
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| +}
|
|
|