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 <stdint.h> | 5 #include <stdint.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 | 7 |
8 #include <limits> | 8 #include <limits> |
9 #include <memory> | 9 #include <memory> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 IPCTestBase::GetChannelName("FuzzServerClient"), &listener)); | 264 IPCTestBase::GetChannelName("FuzzServerClient"), &listener)); |
265 CHECK(channel->Connect()); | 265 CHECK(channel->Connect()); |
266 listener.Init(channel.get()); | 266 listener.Init(channel.get()); |
267 base::MessageLoop::current()->Run(); | 267 base::MessageLoop::current()->Run(); |
268 return 0; | 268 return 0; |
269 } | 269 } |
270 | 270 |
271 class IPCFuzzingTest : public IPCTestBase { | 271 class IPCFuzzingTest : public IPCTestBase { |
272 }; | 272 }; |
273 | 273 |
274 #if defined(OS_ANDROID) | |
275 #define MAYBE_SanityTest DISABLED_SanityTest | |
276 #else | |
277 #define MAYBE_SanityTest SanityTest | |
278 #endif | |
279 // This test makes sure that the FuzzerClientListener and FuzzerServerListener | 274 // This test makes sure that the FuzzerClientListener and FuzzerServerListener |
280 // are working properly by generating two well formed IPC calls. | 275 // are working properly by generating two well formed IPC calls. |
281 TEST_F(IPCFuzzingTest, MAYBE_SanityTest) { | 276 TEST_F(IPCFuzzingTest, SanityTest) { |
282 Init("FuzzServerClient"); | 277 Init("FuzzServerClient"); |
283 | 278 |
284 FuzzerClientListener listener; | 279 FuzzerClientListener listener; |
285 CreateChannel(&listener); | 280 CreateChannel(&listener); |
286 listener.Init(channel()); | 281 listener.Init(channel()); |
287 ASSERT_TRUE(ConnectChannel()); | 282 ASSERT_TRUE(ConnectChannel()); |
288 ASSERT_TRUE(StartClient()); | 283 ASSERT_TRUE(StartClient()); |
289 | 284 |
290 IPC::Message* msg = NULL; | 285 IPC::Message* msg = NULL; |
291 int value = 43; | 286 int value = 43; |
292 msg = new MsgClassIS(value, base::ASCIIToUTF16("expect 43")); | 287 msg = new MsgClassIS(value, base::ASCIIToUTF16("expect 43")); |
293 sender()->Send(msg); | 288 sender()->Send(msg); |
294 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassIS::ID)); | 289 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassIS::ID)); |
295 | 290 |
296 msg = new MsgClassSI(base::ASCIIToUTF16("expect 44"), ++value); | 291 msg = new MsgClassSI(base::ASCIIToUTF16("expect 44"), ++value); |
297 sender()->Send(msg); | 292 sender()->Send(msg); |
298 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassSI::ID)); | 293 EXPECT_TRUE(listener.ExpectMessage(value, MsgClassSI::ID)); |
299 | 294 |
300 EXPECT_TRUE(WaitForClientShutdown()); | 295 EXPECT_TRUE(WaitForClientShutdown()); |
301 DestroyChannel(); | 296 DestroyChannel(); |
302 } | 297 } |
303 | 298 |
304 #if defined(OS_ANDROID) | |
305 #define MAYBE_MsgBadPayloadShort DISABLED_MsgBadPayloadShort | |
306 #else | |
307 #define MAYBE_MsgBadPayloadShort MsgBadPayloadShort | |
308 #endif | |
309 // This test uses a payload that is smaller than expected. This generates an | 299 // This test uses a payload that is smaller than expected. This generates an |
310 // error while unpacking the IPC buffer which in debug trigger an assertion and | 300 // error while unpacking the IPC buffer which in debug trigger an assertion and |
311 // in release is ignored (!). Right after we generate another valid IPC to make | 301 // in release is ignored (!). Right after we generate another valid IPC to make |
312 // sure framing is working properly. | 302 // sure framing is working properly. |
313 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 303 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
314 TEST_F(IPCFuzzingTest, MAYBE_MsgBadPayloadShort) { | 304 TEST_F(IPCFuzzingTest, MsgBadPayloadShort) { |
315 Init("FuzzServerClient"); | 305 Init("FuzzServerClient"); |
316 | 306 |
317 FuzzerClientListener listener; | 307 FuzzerClientListener listener; |
318 CreateChannel(&listener); | 308 CreateChannel(&listener); |
319 listener.Init(channel()); | 309 listener.Init(channel()); |
320 ASSERT_TRUE(ConnectChannel()); | 310 ASSERT_TRUE(ConnectChannel()); |
321 ASSERT_TRUE(StartClient()); | 311 ASSERT_TRUE(StartClient()); |
322 | 312 |
323 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, | 313 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, |
324 IPC::Message::PRIORITY_NORMAL); | 314 IPC::Message::PRIORITY_NORMAL); |
325 msg->WriteInt(666); | 315 msg->WriteInt(666); |
326 sender()->Send(msg); | 316 sender()->Send(msg); |
327 EXPECT_TRUE(listener.ExpectMsgNotHandled(MsgClassIS::ID)); | 317 EXPECT_TRUE(listener.ExpectMsgNotHandled(MsgClassIS::ID)); |
328 | 318 |
329 msg = new MsgClassSI(base::ASCIIToUTF16("expect one"), 1); | 319 msg = new MsgClassSI(base::ASCIIToUTF16("expect one"), 1); |
330 sender()->Send(msg); | 320 sender()->Send(msg); |
331 EXPECT_TRUE(listener.ExpectMessage(1, MsgClassSI::ID)); | 321 EXPECT_TRUE(listener.ExpectMessage(1, MsgClassSI::ID)); |
332 | 322 |
333 EXPECT_TRUE(WaitForClientShutdown()); | 323 EXPECT_TRUE(WaitForClientShutdown()); |
334 DestroyChannel(); | 324 DestroyChannel(); |
335 } | 325 } |
336 #endif | 326 #endif |
337 | 327 |
338 #if defined(OS_ANDROID) | |
339 #define MAYBE_MsgBadPayloadArgs DISABLED_MsgBadPayloadArgs | |
340 #else | |
341 #define MAYBE_MsgBadPayloadArgs MsgBadPayloadArgs | |
342 #endif | |
343 // This test uses a payload that has too many arguments, but so the payload size | 328 // This test uses a payload that has too many arguments, but so the payload size |
344 // is big enough so the unpacking routine does not generate an error as in the | 329 // is big enough so the unpacking routine does not generate an error as in the |
345 // case of MsgBadPayloadShort test. This test does not pinpoint a flaw (per se) | 330 // case of MsgBadPayloadShort test. This test does not pinpoint a flaw (per se) |
346 // as by design we don't carry type information on the IPC message. | 331 // as by design we don't carry type information on the IPC message. |
347 TEST_F(IPCFuzzingTest, MAYBE_MsgBadPayloadArgs) { | 332 TEST_F(IPCFuzzingTest, MsgBadPayloadArgs) { |
348 Init("FuzzServerClient"); | 333 Init("FuzzServerClient"); |
349 | 334 |
350 FuzzerClientListener listener; | 335 FuzzerClientListener listener; |
351 CreateChannel(&listener); | 336 CreateChannel(&listener); |
352 listener.Init(channel()); | 337 listener.Init(channel()); |
353 ASSERT_TRUE(ConnectChannel()); | 338 ASSERT_TRUE(ConnectChannel()); |
354 ASSERT_TRUE(StartClient()); | 339 ASSERT_TRUE(StartClient()); |
355 | 340 |
356 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassSI::ID, | 341 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassSI::ID, |
357 IPC::Message::PRIORITY_NORMAL); | 342 IPC::Message::PRIORITY_NORMAL); |
358 msg->WriteString16(base::ASCIIToUTF16("d")); | 343 msg->WriteString16(base::ASCIIToUTF16("d")); |
359 msg->WriteInt(0); | 344 msg->WriteInt(0); |
360 msg->WriteInt(0x65); // Extra argument. | 345 msg->WriteInt(0x65); // Extra argument. |
361 | 346 |
362 sender()->Send(msg); | 347 sender()->Send(msg); |
363 EXPECT_TRUE(listener.ExpectMessage(0, MsgClassSI::ID)); | 348 EXPECT_TRUE(listener.ExpectMessage(0, MsgClassSI::ID)); |
364 | 349 |
365 // Now send a well formed message to make sure the receiver wasn't | 350 // Now send a well formed message to make sure the receiver wasn't |
366 // thrown out of sync by the extra argument. | 351 // thrown out of sync by the extra argument. |
367 msg = new MsgClassIS(3, base::ASCIIToUTF16("expect three")); | 352 msg = new MsgClassIS(3, base::ASCIIToUTF16("expect three")); |
368 sender()->Send(msg); | 353 sender()->Send(msg); |
369 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID)); | 354 EXPECT_TRUE(listener.ExpectMessage(3, MsgClassIS::ID)); |
370 | 355 |
371 EXPECT_TRUE(WaitForClientShutdown()); | 356 EXPECT_TRUE(WaitForClientShutdown()); |
372 DestroyChannel(); | 357 DestroyChannel(); |
373 } | 358 } |
374 | 359 |
375 } // namespace | 360 } // namespace |
OLD | NEW |