| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <stdio.h> | 5 #include <stdio.h> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 304 |
| 305 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000)); | 305 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000)); |
| 306 base::CloseProcessHandle(server_process); | 306 base::CloseProcessHandle(server_process); |
| 307 } | 307 } |
| 308 | 308 |
| 309 // This test uses a payload that is smaller than expected. | 309 // This test uses a payload that is smaller than expected. |
| 310 // This generates an error while unpacking the IPC buffer which in | 310 // This generates an error while unpacking the IPC buffer which in |
| 311 // In debug this triggers an assertion and in release it is ignored(!!). Right | 311 // In debug this triggers an assertion and in release it is ignored(!!). Right |
| 312 // after we generate another valid IPC to make sure framing is working | 312 // after we generate another valid IPC to make sure framing is working |
| 313 // properly. | 313 // properly. |
| 314 #ifdef NDEBUG | 314 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
| 315 TEST_F(IPCFuzzingTest, MsgBadPayloadShort) { | 315 TEST_F(IPCFuzzingTest, MsgBadPayloadShort) { |
| 316 FuzzerClientListener listener; | 316 FuzzerClientListener listener; |
| 317 IPC::Channel chan(kFuzzerChannel, IPC::Channel::MODE_SERVER, | 317 IPC::Channel chan(kFuzzerChannel, IPC::Channel::MODE_SERVER, |
| 318 &listener); | 318 &listener); |
| 319 base::ProcessHandle server_process = SpawnChild(FUZZER_SERVER, &chan); | 319 base::ProcessHandle server_process = SpawnChild(FUZZER_SERVER, &chan); |
| 320 ASSERT_TRUE(server_process); | 320 ASSERT_TRUE(server_process); |
| 321 base::PlatformThread::Sleep(1000); | 321 base::PlatformThread::Sleep(1000); |
| 322 ASSERT_TRUE(chan.Connect()); | 322 ASSERT_TRUE(chan.Connect()); |
| 323 listener.Init(&chan); | 323 listener.Init(&chan); |
| 324 | 324 |
| 325 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, | 325 IPC::Message* msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, |
| 326 IPC::Message::PRIORITY_NORMAL); | 326 IPC::Message::PRIORITY_NORMAL); |
| 327 msg->WriteInt(666); | 327 msg->WriteInt(666); |
| 328 chan.Send(msg); | 328 chan.Send(msg); |
| 329 EXPECT_TRUE(listener.ExpectMsgNotHandled(MsgClassIS::ID)); | 329 EXPECT_TRUE(listener.ExpectMsgNotHandled(MsgClassIS::ID)); |
| 330 | 330 |
| 331 msg = new MsgClassSI(L"expect one", 1); | 331 msg = new MsgClassSI(L"expect one", 1); |
| 332 chan.Send(msg); | 332 chan.Send(msg); |
| 333 EXPECT_TRUE(listener.ExpectMessage(1, MsgClassSI::ID)); | 333 EXPECT_TRUE(listener.ExpectMessage(1, MsgClassSI::ID)); |
| 334 | 334 |
| 335 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000)); | 335 EXPECT_TRUE(base::WaitForSingleProcess(server_process, 5000)); |
| 336 base::CloseProcessHandle(server_process); | 336 base::CloseProcessHandle(server_process); |
| 337 } | 337 } |
| 338 #endif // NDEBUG | 338 #endif |
| 339 | 339 |
| 340 // This test uses a payload that has too many arguments, but so the payload | 340 // This test uses a payload that has too many arguments, but so the payload |
| 341 // size is big enough so the unpacking routine does not generate an error as | 341 // size is big enough so the unpacking routine does not generate an error as |
| 342 // in the case of MsgBadPayloadShort test. | 342 // in the case of MsgBadPayloadShort test. |
| 343 // This test does not pinpoint a flaw (per se) as by design we don't carry | 343 // This test does not pinpoint a flaw (per se) as by design we don't carry |
| 344 // type information on the IPC message. | 344 // type information on the IPC message. |
| 345 TEST_F(IPCFuzzingTest, MsgBadPayloadArgs) { | 345 TEST_F(IPCFuzzingTest, MsgBadPayloadArgs) { |
| 346 FuzzerClientListener listener; | 346 FuzzerClientListener listener; |
| 347 IPC::Channel chan(kFuzzerChannel, IPC::Channel::MODE_SERVER, | 347 IPC::Channel chan(kFuzzerChannel, IPC::Channel::MODE_SERVER, |
| 348 &listener); | 348 &listener); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 ServerMacroExTest server; | 406 ServerMacroExTest server; |
| 407 | 407 |
| 408 // Test the regular messages. | 408 // Test the regular messages. |
| 409 msg = new MsgClassIS(3, L"text3"); | 409 msg = new MsgClassIS(3, L"text3"); |
| 410 EXPECT_TRUE(server.OnMessageReceived(*msg)); | 410 EXPECT_TRUE(server.OnMessageReceived(*msg)); |
| 411 delete msg; | 411 delete msg; |
| 412 msg = new MsgClassSI(L"text2", 2); | 412 msg = new MsgClassSI(L"text2", 2); |
| 413 EXPECT_TRUE(server.OnMessageReceived(*msg)); | 413 EXPECT_TRUE(server.OnMessageReceived(*msg)); |
| 414 delete msg; | 414 delete msg; |
| 415 | 415 |
| 416 #ifdef NDEBUG | 416 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
| 417 // Test a bad message. | 417 // Test a bad message. |
| 418 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassSI::ID, | 418 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassSI::ID, |
| 419 IPC::Message::PRIORITY_NORMAL); | 419 IPC::Message::PRIORITY_NORMAL); |
| 420 msg->WriteInt(2); | 420 msg->WriteInt(2); |
| 421 EXPECT_FALSE(server.OnMessageReceived(*msg)); | 421 EXPECT_FALSE(server.OnMessageReceived(*msg)); |
| 422 delete msg; | 422 delete msg; |
| 423 | 423 |
| 424 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, | 424 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, |
| 425 IPC::Message::PRIORITY_NORMAL); | 425 IPC::Message::PRIORITY_NORMAL); |
| 426 msg->WriteInt(0x64); | 426 msg->WriteInt(0x64); |
| 427 msg->WriteInt(0x32); | 427 msg->WriteInt(0x32); |
| 428 EXPECT_FALSE(server.OnMessageReceived(*msg)); | 428 EXPECT_FALSE(server.OnMessageReceived(*msg)); |
| 429 delete msg; | 429 delete msg; |
| 430 | 430 |
| 431 EXPECT_EQ(0, server.unhandled_msgs()); | 431 EXPECT_EQ(0, server.unhandled_msgs()); |
| 432 #endif | 432 #endif |
| 433 } | 433 } |
| OLD | NEW |