Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: ipc/ipc_fuzzing_tests.cc

Issue 7768001: Add support for exporting IPC messages from component DLLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/content_common.gypi ('k') | ipc/ipc_message_macros.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/threading/platform_thread.h" 11 #include "base/threading/platform_thread.h"
12 #include "ipc/ipc_channel.h" 12 #include "ipc/ipc_channel.h"
13 #include "ipc/ipc_channel_proxy.h" 13 #include "ipc/ipc_channel_proxy.h"
14 #include "ipc/ipc_message_utils.h"
15 #include "ipc/ipc_message_utils_impl.h"
16 #include "ipc/ipc_tests.h" 14 #include "ipc/ipc_tests.h"
17 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
18 #include "testing/multiprocess_func_list.h" 16 #include "testing/multiprocess_func_list.h"
19 17
18 // IPC messages for testing ---------------------------------------------------
19
20 #define IPC_MESSAGE_IMPL
21 #include "ipc/ipc_message_macros.h"
22
23 #define IPC_MESSAGE_START TestMsgStart
24
25 // Generic message class that is an int followed by a wstring.
26 IPC_MESSAGE_CONTROL2(MsgClassIS, int, std::wstring)
27
28 // Generic message class that is a wstring followed by an int.
29 IPC_MESSAGE_CONTROL2(MsgClassSI, std::wstring, int)
30
31 // Message to create a mutex in the IPC server, using the received name.
32 IPC_MESSAGE_CONTROL2(MsgDoMutex, std::wstring, int)
33
34 // Used to generate an ID for a message that should not exist.
35 IPC_MESSAGE_CONTROL0(MsgUnhandled)
36
37 // ----------------------------------------------------------------------------
38
20 TEST(IPCMessageIntegrity, ReadBeyondBufferStr) { 39 TEST(IPCMessageIntegrity, ReadBeyondBufferStr) {
21 //This was BUG 984408. 40 //This was BUG 984408.
22 uint32 v1 = kuint32max - 1; 41 uint32 v1 = kuint32max - 1;
23 int v2 = 666; 42 int v2 = 666;
24 IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); 43 IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL);
25 EXPECT_TRUE(m.WriteInt(v1)); 44 EXPECT_TRUE(m.WriteInt(v1));
26 EXPECT_TRUE(m.WriteInt(v2)); 45 EXPECT_TRUE(m.WriteInt(v2));
27 46
28 void* iter = NULL; 47 void* iter = NULL;
29 std::string vs; 48 std::string vs;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL); 108 IPC::Message m(0, 1, IPC::Message::PRIORITY_NORMAL);
90 EXPECT_TRUE(m.WriteInt(0x71000000)); // This is the count of elements. 109 EXPECT_TRUE(m.WriteInt(0x71000000)); // This is the count of elements.
91 EXPECT_TRUE(m.WriteInt64(1)); 110 EXPECT_TRUE(m.WriteInt64(1));
92 EXPECT_TRUE(m.WriteInt64(2)); 111 EXPECT_TRUE(m.WriteInt64(2));
93 112
94 std::vector<int64> vec; 113 std::vector<int64> vec;
95 void* iter = 0; 114 void* iter = 0;
96 EXPECT_FALSE(ReadParam(&m, &iter, &vec)); 115 EXPECT_FALSE(ReadParam(&m, &iter, &vec));
97 } 116 }
98 117
99 // We don't actually use the messages defined in this file, but we do this
100 // to get to the IPC macros.
101 #include "ipc/ipc_sync_message_unittest.h"
102
103 enum IPCMessageIds {
104 UNUSED_IPC_TYPE,
105 SERVER_FIRST_IPC_TYPE, // 1st Test message tag.
106 SERVER_SECOND_IPC_TYPE, // 2nd Test message tag.
107 SERVER_THIRD_IPC_TYPE, // 3rd Test message tag.
108 CLIENT_MALFORMED_IPC, // Sent to client if server detects bad message.
109 CLIENT_UNHANDLED_IPC // Sent to client if server detects unhanded IPC.
110 };
111
112 // Generic message class that is an int followed by a wstring.
113 class MsgClassIS : public IPC::MessageWithTuple< Tuple2<int, std::wstring> > {
114 public:
115 enum { ID = SERVER_FIRST_IPC_TYPE };
116 MsgClassIS(const int& arg1, const std::wstring& arg2)
117 : IPC::MessageWithTuple< Tuple2<int, std::wstring> >(
118 MSG_ROUTING_CONTROL, ID, MakeRefTuple(arg1, arg2)) {}
119 };
120
121 // Generic message class that is a wstring followed by an int.
122 class MsgClassSI : public IPC::MessageWithTuple< Tuple2<std::wstring, int> > {
123 public:
124 enum { ID = SERVER_SECOND_IPC_TYPE };
125 MsgClassSI(const std::wstring& arg1, const int& arg2)
126 : IPC::MessageWithTuple< Tuple2<std::wstring, int> >(
127 MSG_ROUTING_CONTROL, ID, MakeRefTuple(arg1, arg2)) {}
128 };
129
130 // Message to create a mutex in the IPC server, using the received name.
131 class MsgDoMutex : public IPC::MessageWithTuple< Tuple2<std::wstring, int> > {
132 public:
133 enum { ID = SERVER_THIRD_IPC_TYPE };
134 MsgDoMutex(const std::wstring& mutex_name, const int& unused)
135 : IPC::MessageWithTuple< Tuple2<std::wstring, int> >(
136 MSG_ROUTING_CONTROL, ID, MakeRefTuple(mutex_name, unused)) {}
137 };
138
139 class SimpleListener : public IPC::Channel::Listener { 118 class SimpleListener : public IPC::Channel::Listener {
140 public: 119 public:
141 SimpleListener() : other_(NULL) { 120 SimpleListener() : other_(NULL) {
142 } 121 }
143 void Init(IPC::Message::Sender* s) { 122 void Init(IPC::Message::Sender* s) {
144 other_ = s; 123 other_ = s;
145 } 124 }
146 protected: 125 protected:
147 IPC::Message::Sender* other_; 126 IPC::Message::Sender* other_;
148 }; 127 };
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 174 }
196 175
197 void Cleanup() { 176 void Cleanup() {
198 --message_count_; 177 --message_count_;
199 --pending_messages_; 178 --pending_messages_;
200 if (0 == message_count_) 179 if (0 == message_count_)
201 MessageLoop::current()->Quit(); 180 MessageLoop::current()->Quit();
202 } 181 }
203 182
204 void ReplyMsgNotHandled(uint32 type_id) { 183 void ReplyMsgNotHandled(uint32 type_id) {
205 RoundtripAckReply(FUZZER_ROUTING_ID, CLIENT_UNHANDLED_IPC, type_id); 184 RoundtripAckReply(FUZZER_ROUTING_ID, MsgUnhandled::ID, type_id);
206 Cleanup(); 185 Cleanup();
207 } 186 }
208 187
209 void UseData(int caller, int value, const std::wstring& text) { 188 void UseData(int caller, int value, const std::wstring& text) {
210 std::wostringstream wos; 189 std::wostringstream wos;
211 wos << L"IPC fuzzer:" << caller << " [" << value << L" " << text << L"]\n"; 190 wos << L"IPC fuzzer:" << caller << " [" << value << L" " << text << L"]\n";
212 std::wstring output = wos.str(); 191 std::wstring output = wos.str();
213 LOG(WARNING) << output.c_str(); 192 LOG(WARNING) << output.c_str();
214 }; 193 };
215 194
(...skipping 26 matching lines...) Expand all
242 return false; 221 return false;
243 if (msg_value2 != value) 222 if (msg_value2 != value)
244 return false; 223 return false;
245 224
246 delete last_msg_; 225 delete last_msg_;
247 last_msg_ = NULL; 226 last_msg_ = NULL;
248 return true; 227 return true;
249 } 228 }
250 229
251 bool ExpectMsgNotHandled(uint32 type_id) { 230 bool ExpectMsgNotHandled(uint32 type_id) {
252 return ExpectMessage(type_id, CLIENT_UNHANDLED_IPC); 231 return ExpectMessage(type_id, MsgUnhandled::ID);
253 } 232 }
254 233
255 private: 234 private:
256 bool MsgHandlerInternal(uint32 type_id) { 235 bool MsgHandlerInternal(uint32 type_id) {
257 MessageLoop::current()->Run(); 236 MessageLoop::current()->Run();
258 if (NULL == last_msg_) 237 if (NULL == last_msg_)
259 return false; 238 return false;
260 if (FUZZER_ROUTING_ID != last_msg_->routing_id()) 239 if (FUZZER_ROUTING_ID != last_msg_->routing_id())
261 return false; 240 return false;
262 return (type_id == last_msg_->type()); 241 return (type_id == last_msg_->type());
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID, 403 msg = new IPC::Message(MSG_ROUTING_CONTROL, MsgClassIS::ID,
425 IPC::Message::PRIORITY_NORMAL); 404 IPC::Message::PRIORITY_NORMAL);
426 msg->WriteInt(0x64); 405 msg->WriteInt(0x64);
427 msg->WriteInt(0x32); 406 msg->WriteInt(0x32);
428 EXPECT_FALSE(server.OnMessageReceived(*msg)); 407 EXPECT_FALSE(server.OnMessageReceived(*msg));
429 delete msg; 408 delete msg;
430 409
431 EXPECT_EQ(0, server.unhandled_msgs()); 410 EXPECT_EQ(0, server.unhandled_msgs());
432 #endif 411 #endif
433 } 412 }
OLDNEW
« no previous file with comments | « content/content_common.gypi ('k') | ipc/ipc_message_macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698