OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2013 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 #include "native_client/src/trusted/validator/validation_cache.h" |
| 8 |
| 9 #include "native_client/src/shared/platform/nacl_check.h" |
| 10 #include "native_client/src/trusted/validator/validation_metadata.h" |
| 11 |
| 12 #define ADD_LITERAL(cache, query, data) \ |
| 13 ((cache)->AddData((query), (uint8_t*)&(data), sizeof(data))) |
| 14 |
| 15 void AddCodeIdentity(uint8_t *data, |
| 16 size_t size, |
| 17 const struct NaClValidationMetadata *metadata, |
| 18 struct NaClValidationCache *cache, |
| 19 void *query) { |
| 20 NaClCodeIdentityType identity_type; |
| 21 if (NULL != metadata) { |
| 22 identity_type = metadata->identity_type; |
| 23 } else { |
| 24 /* Fallback: identity unknown, treat it as anonymous data. */ |
| 25 identity_type = NaClCodeIdentityData; |
| 26 } |
| 27 CHECK(identity_type < NaClCodeIdentityMax); |
| 28 |
| 29 /* |
| 30 * Explicitly record the type of identity being used to prevent attacks |
| 31 * that confuse the payload of different identity types. |
| 32 */ |
| 33 ADD_LITERAL(cache, query, identity_type); |
| 34 |
| 35 if (identity_type == NaClCodeIdentityFile) { |
| 36 /* Sanity checks. */ |
| 37 CHECK(metadata->file_name); |
| 38 CHECK(metadata->file_name_length); |
| 39 CHECK(metadata->code_offset + (int64_t) size <= metadata->file_size); |
| 40 |
| 41 /* The location of the code in the file. */ |
| 42 ADD_LITERAL(cache, query, metadata->code_offset); |
| 43 ADD_LITERAL(cache, query, size); |
| 44 |
| 45 /* The identity of the file. */ |
| 46 cache->AddData(query, (uint8_t *) metadata->file_name, |
| 47 metadata->file_name_length); |
| 48 ADD_LITERAL(cache, query, metadata->file_size); |
| 49 ADD_LITERAL(cache, query, metadata->mtime); |
| 50 } else { |
| 51 /* Hash all the code. */ |
| 52 cache->AddData(query, data, size); |
| 53 } |
| 54 } |
OLD | NEW |