OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/policy/preg_parser_win.h" | 5 #include "chrome/browser/policy/preg_parser_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 return -1; | 57 return -1; |
58 | 58 |
59 int result = **cursor | (*(*cursor + 1) << 8); | 59 int result = **cursor | (*(*cursor + 1) << 8); |
60 *cursor += sizeof(char16); | 60 *cursor += sizeof(char16); |
61 return result; | 61 return result; |
62 } | 62 } |
63 | 63 |
64 // Reads a fixed-size field from a PReg file. | 64 // Reads a fixed-size field from a PReg file. |
65 bool ReadFieldBinary(const uint8** cursor, | 65 bool ReadFieldBinary(const uint8** cursor, |
66 const uint8* end, | 66 const uint8* end, |
67 int size, | 67 uint32 size, |
68 uint8* data) { | 68 uint8* data) { |
69 if (!size) | 69 if (size == 0) |
70 return false; | 70 return true; |
71 | |
71 const uint8* field_end = *cursor + size; | 72 const uint8* field_end = *cursor + size; |
72 if (field_end > end) | 73 if (field_end <= *cursor || field_end > end) |
Joao da Silva
2013/09/13 14:18:07
if this accepted "field_end == *cursor" then it wo
Mattias Nissler (ping if slow)
2013/09/13 14:40:24
The size == 0 check is here to handle the case of
| |
73 return false; | 74 return false; |
74 std::copy(*cursor, field_end, data); | 75 std::copy(*cursor, field_end, data); |
75 *cursor = field_end; | 76 *cursor = field_end; |
76 return true; | 77 return true; |
77 } | 78 } |
78 | 79 |
79 bool ReadField32(const uint8** cursor, const uint8* end, uint32* data) { | 80 bool ReadField32(const uint8** cursor, const uint8* end, uint32* data) { |
80 uint32 value = 0; | 81 uint32 value = 0; |
81 if (!ReadFieldBinary(cursor, end, sizeof(uint32), | 82 if (!ReadFieldBinary(cursor, end, sizeof(uint32), |
82 reinterpret_cast<uint8*>(&value))) { | 83 reinterpret_cast<uint8*>(&value))) { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 } | 297 } |
297 | 298 |
298 LOG(ERROR) << "Error parsing " << file_path.value() << " at offset " | 299 LOG(ERROR) << "Error parsing " << file_path.value() << " at offset " |
299 << reinterpret_cast<const uint8*>(cursor - 1) - mapped_file.data(); | 300 << reinterpret_cast<const uint8*>(cursor - 1) - mapped_file.data(); |
300 status->Add(POLICY_LOAD_STATUS_PARSE_ERROR); | 301 status->Add(POLICY_LOAD_STATUS_PARSE_ERROR); |
301 return false; | 302 return false; |
302 } | 303 } |
303 | 304 |
304 } // namespace preg_parser | 305 } // namespace preg_parser |
305 } // namespace policy | 306 } // namespace policy |
OLD | NEW |