OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ipc/ipc_message.h" | 5 #include "ipc/ipc_message.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
11 #include <limits> | 11 #include <limits> |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "ipc/attachment_broker.h" | |
18 #include "ipc/ipc_message_utils.h" | 17 #include "ipc/ipc_message_utils.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
20 | 19 |
21 // IPC messages for testing ---------------------------------------------------- | 20 // IPC messages for testing ---------------------------------------------------- |
22 | 21 |
23 #define IPC_MESSAGE_IMPL | 22 #define IPC_MESSAGE_IMPL |
24 #include "ipc/ipc_message_macros.h" | 23 #include "ipc/ipc_message_macros.h" |
25 | 24 |
26 #define IPC_MESSAGE_START TestMsgStart | 25 #define IPC_MESSAGE_START TestMsgStart |
27 | 26 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 IPC::Message::FindNext(data_start, data_end, &next); | 144 IPC::Message::FindNext(data_start, data_end, &next); |
146 EXPECT_TRUE(next.message_found); | 145 EXPECT_TRUE(next.message_found); |
147 EXPECT_EQ(next.message_size, message.size()); | 146 EXPECT_EQ(next.message_size, message.size()); |
148 EXPECT_EQ(next.pickle_end, data_end); | 147 EXPECT_EQ(next.pickle_end, data_end); |
149 EXPECT_EQ(next.message_end, data_end); | 148 EXPECT_EQ(next.message_end, data_end); |
150 | 149 |
151 // Data range doesn't contain the entire message | 150 // Data range doesn't contain the entire message |
152 // (but contains the message header) | 151 // (but contains the message header) |
153 IPC::Message::FindNext(data_start, data_end - 1, &next); | 152 IPC::Message::FindNext(data_start, data_end - 1, &next); |
154 EXPECT_FALSE(next.message_found); | 153 EXPECT_FALSE(next.message_found); |
155 #if USE_ATTACHMENT_BROKER | |
156 EXPECT_EQ(next.message_size, 0u); | |
157 #else | |
158 EXPECT_EQ(next.message_size, message.size()); | 154 EXPECT_EQ(next.message_size, message.size()); |
159 #endif | |
160 | 155 |
161 // Data range doesn't contain the message header | 156 // Data range doesn't contain the message header |
162 // (but contains the pickle header) | 157 // (but contains the pickle header) |
163 IPC::Message::FindNext(data_start, | 158 IPC::Message::FindNext(data_start, |
164 data_start + sizeof(IPC::Message::Header) - 1, | 159 data_start + sizeof(IPC::Message::Header) - 1, |
165 &next); | 160 &next); |
166 EXPECT_FALSE(next.message_found); | 161 EXPECT_FALSE(next.message_found); |
167 EXPECT_EQ(next.message_size, 0u); | 162 EXPECT_EQ(next.message_size, 0u); |
168 | 163 |
169 // Data range doesn't contain the pickle header | 164 // Data range doesn't contain the pickle header |
(...skipping 11 matching lines...) Expand all Loading... |
181 | 176 |
182 const char* data_start = reinterpret_cast<const char*>(message.data()); | 177 const char* data_start = reinterpret_cast<const char*>(message.data()); |
183 const char* data_end = data_start + message.size(); | 178 const char* data_end = data_start + message.size(); |
184 | 179 |
185 IPC::Message::NextMessageInfo next; | 180 IPC::Message::NextMessageInfo next; |
186 | 181 |
187 // Payload size is negative (defeats 'start + size > end' check) | 182 // Payload size is negative (defeats 'start + size > end' check) |
188 message.header()->payload_size = static_cast<uint32_t>(-1); | 183 message.header()->payload_size = static_cast<uint32_t>(-1); |
189 IPC::Message::FindNext(data_start, data_end, &next); | 184 IPC::Message::FindNext(data_start, data_end, &next); |
190 EXPECT_FALSE(next.message_found); | 185 EXPECT_FALSE(next.message_found); |
191 #if USE_ATTACHMENT_BROKER | |
192 EXPECT_EQ(next.message_size, 0u); | |
193 #else | |
194 if (sizeof(size_t) > sizeof(uint32_t)) { | 186 if (sizeof(size_t) > sizeof(uint32_t)) { |
195 // No overflow, just insane message size | 187 // No overflow, just insane message size |
196 EXPECT_EQ(next.message_size, | 188 EXPECT_EQ(next.message_size, |
197 message.header()->payload_size + sizeof(IPC::Message::Header)); | 189 message.header()->payload_size + sizeof(IPC::Message::Header)); |
198 } else { | 190 } else { |
199 // Actual overflow, reported as max size_t | 191 // Actual overflow, reported as max size_t |
200 EXPECT_EQ(next.message_size, std::numeric_limits<size_t>::max()); | 192 EXPECT_EQ(next.message_size, std::numeric_limits<size_t>::max()); |
201 } | 193 } |
202 #endif | |
203 | 194 |
204 // Payload size is max positive integer (defeats size < 0 check, while | 195 // Payload size is max positive integer (defeats size < 0 check, while |
205 // still potentially causing overflow down the road). | 196 // still potentially causing overflow down the road). |
206 message.header()->payload_size = std::numeric_limits<int32_t>::max(); | 197 message.header()->payload_size = std::numeric_limits<int32_t>::max(); |
207 IPC::Message::FindNext(data_start, data_end, &next); | 198 IPC::Message::FindNext(data_start, data_end, &next); |
208 EXPECT_FALSE(next.message_found); | 199 EXPECT_FALSE(next.message_found); |
209 #if USE_ATTACHMENT_BROKER | |
210 EXPECT_EQ(next.message_size, 0u); | |
211 #else | |
212 EXPECT_EQ(next.message_size, | 200 EXPECT_EQ(next.message_size, |
213 message.header()->payload_size + sizeof(IPC::Message::Header)); | 201 message.header()->payload_size + sizeof(IPC::Message::Header)); |
214 #endif | |
215 } | 202 } |
216 | 203 |
217 namespace { | 204 namespace { |
218 | 205 |
219 class IPCMessageParameterTest : public testing::Test { | 206 class IPCMessageParameterTest : public testing::Test { |
220 public: | 207 public: |
221 IPCMessageParameterTest() : extra_param_("extra_param"), called_(false) {} | 208 IPCMessageParameterTest() : extra_param_("extra_param"), called_(false) {} |
222 | 209 |
223 bool OnMessageReceived(const IPC::Message& message) { | 210 bool OnMessageReceived(const IPC::Message& message) { |
224 bool handled = true; | 211 bool handled = true; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 /* TODO: handle sync IPCs | 270 /* TODO: handle sync IPCs |
284 TEST_F(IPCMessageParameterTest, Sync) { | 271 TEST_F(IPCMessageParameterTest, Sync) { |
285 std::string output; | 272 std::string output; |
286 TestMsgClassIS message(42, &output); | 273 TestMsgClassIS message(42, &output); |
287 EXPECT_TRUE(OnMessageReceived(message)); | 274 EXPECT_TRUE(OnMessageReceived(message)); |
288 EXPECT_TRUE(called_); | 275 EXPECT_TRUE(called_); |
289 EXPECT_EQ(output, std::string("out")); | 276 EXPECT_EQ(output, std::string("out")); |
290 }*/ | 277 }*/ |
291 | 278 |
292 } // namespace IPC | 279 } // namespace IPC |
OLD | NEW |