1 : /*
2 : * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 :
8 : /* NaCl inter-module communication primitives. */
9 :
10 : /* Used for UINT32_MAX */
11 : #if !NACL_WINDOWS
12 : # ifndef __STDC_LIMIT_MACROS
13 : # define __STDC_LIMIT_MACROS
14 : # endif
15 : #include <stdint.h>
16 : #endif
17 :
18 : /* TODO(robertm): stdio.h is included for NULL only - find a better way */
19 : #include <stdio.h>
20 :
21 : #include "native_client/src/include/portability.h"
22 :
23 : #include "native_client/src/shared/imc/nacl_imc_c.h"
24 : #include "native_client/src/shared/platform/nacl_log.h"
25 :
26 :
27 5 : int NaClMessageSizeIsValid(const NaClMessageHeader *message) {
28 5 : size_t cur_bytes = 0;
29 : static size_t const kMax = ~(uint32_t) 0;
30 : size_t ix;
31 : /* we assume that sizeof(uint32_t) <= sizeof(size_t) */
32 :
33 5 : for (ix = 0; ix < message->iov_length; ++ix) {
34 5 : if (kMax - cur_bytes < message->iov[ix].length) {
35 0 : return 0;
36 : }
37 5 : cur_bytes += message->iov[ix].length; /* no overflow is possible */
38 5 : }
39 5 : return 1;
40 5 : }
|