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

Side by Side Diff: sandbox/mac/bootstrap_sandbox_unittest.mm

Issue 306123012: Do not double-unref send rights when using POLICY_SUBSTITUE_PORT. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adjust comment Created 6 years, 6 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 | « no previous file | sandbox/mac/launchd_interception_server.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "sandbox/mac/bootstrap_sandbox.h" 5 #include "sandbox/mac/bootstrap_sandbox.h"
6 6
7 #include <CoreFoundation/CoreFoundation.h> 7 #include <CoreFoundation/CoreFoundation.h>
8 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 #include <mach/mach.h> 9 #include <mach/mach.h>
10 #include <servers/bootstrap.h> 10 #include <servers/bootstrap.h>
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 char buf[32]; 218 char buf[32];
219 }; 219 };
220 220
221 struct SubstitutePortAckRecv : public SubstitutePortAckSend { 221 struct SubstitutePortAckRecv : public SubstitutePortAckSend {
222 mach_msg_trailer_t trailer; 222 mach_msg_trailer_t trailer;
223 }; 223 };
224 224
225 const char kSubstituteAck[] = "Hello, this is doge!"; 225 const char kSubstituteAck[] = "Hello, this is doge!";
226 226
227 TEST_F(BootstrapSandboxTest, PolicySubstitutePort) { 227 TEST_F(BootstrapSandboxTest, PolicySubstitutePort) {
228 mach_port_t task = mach_task_self();
229
228 mach_port_t port; 230 mach_port_t port;
229 ASSERT_EQ(KERN_SUCCESS, mach_port_allocate(mach_task_self(), 231 ASSERT_EQ(KERN_SUCCESS, mach_port_allocate(task, MACH_PORT_RIGHT_RECEIVE,
230 MACH_PORT_RIGHT_RECEIVE, &port)); 232 &port));
231 base::mac::ScopedMachReceiveRight scoped_port(port); 233 base::mac::ScopedMachReceiveRight scoped_port(port);
232 234
235 mach_port_urefs_t send_rights = 0;
236 ASSERT_EQ(KERN_SUCCESS, mach_port_get_refs(task, port, MACH_PORT_RIGHT_SEND,
237 &send_rights));
238 EXPECT_EQ(0u, send_rights);
239
240 ASSERT_EQ(KERN_SUCCESS, mach_port_insert_right(task, port, port,
241 MACH_MSG_TYPE_MAKE_SEND));
242 base::mac::ScopedMachSendRight scoped_port_send(port);
243
244 send_rights = 0;
245 ASSERT_EQ(KERN_SUCCESS, mach_port_get_refs(task, port, MACH_PORT_RIGHT_SEND,
246 &send_rights));
247 EXPECT_EQ(1u, send_rights);
248
233 BootstrapSandboxPolicy policy(BaselinePolicy()); 249 BootstrapSandboxPolicy policy(BaselinePolicy());
234 policy[kTestServer] = Rule(port); 250 policy[kTestServer] = Rule(port);
235 sandbox_->RegisterSandboxPolicy(1, policy); 251 sandbox_->RegisterSandboxPolicy(1, policy);
236 252
237 RunChildWithPolicy(1, "PolicySubstitutePort", NULL); 253 RunChildWithPolicy(1, "PolicySubstitutePort", NULL);
238 254
239 struct SubstitutePortAckRecv msg; 255 struct SubstitutePortAckRecv msg;
240 bzero(&msg, sizeof(msg)); 256 bzero(&msg, sizeof(msg));
241 msg.header.msgh_size = sizeof(msg); 257 msg.header.msgh_size = sizeof(msg);
242 msg.header.msgh_local_port = port; 258 msg.header.msgh_local_port = port;
243 kern_return_t kr = mach_msg(&msg.header, MACH_RCV_MSG, 0, 259 kern_return_t kr = mach_msg(&msg.header, MACH_RCV_MSG, 0,
244 msg.header.msgh_size, port, 260 msg.header.msgh_size, port,
245 TestTimeouts::tiny_timeout().InMilliseconds(), MACH_PORT_NULL); 261 TestTimeouts::tiny_timeout().InMilliseconds(), MACH_PORT_NULL);
246 EXPECT_EQ(KERN_SUCCESS, kr); 262 EXPECT_EQ(KERN_SUCCESS, kr);
247 263
264 send_rights = 0;
265 ASSERT_EQ(KERN_SUCCESS, mach_port_get_refs(task, port, MACH_PORT_RIGHT_SEND,
266 &send_rights));
267 EXPECT_EQ(1u, send_rights);
268
248 EXPECT_EQ(0, strncmp(kSubstituteAck, msg.buf, sizeof(msg.buf))); 269 EXPECT_EQ(0, strncmp(kSubstituteAck, msg.buf, sizeof(msg.buf)));
249 } 270 }
250 271
251 MULTIPROCESS_TEST_MAIN(PolicySubstitutePort) { 272 MULTIPROCESS_TEST_MAIN(PolicySubstitutePort) {
252 mach_port_t port = MACH_PORT_NULL; 273 mach_port_t port = MACH_PORT_NULL;
253 kern_return_t kr = bootstrap_look_up(bootstrap_port, kTestServer, &port); 274 kern_return_t kr = bootstrap_look_up(bootstrap_port, kTestServer, &port);
254 CHECK_EQ(KERN_SUCCESS, kr); 275 CHECK_EQ(KERN_SUCCESS, kr);
255 CHECK(port != MACH_PORT_NULL); 276 CHECK(port != MACH_PORT_NULL);
256 277
257 struct SubstitutePortAckSend msg; 278 struct SubstitutePortAckSend msg;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 EXPECT_EQ(KERN_SUCCESS, bootstrap_look_up(bp, service_name, &service_port)); 329 EXPECT_EQ(KERN_SUCCESS, bootstrap_look_up(bp, service_name, &service_port));
309 base::mac::ScopedMachSendRight scoped_service_port(service_port); 330 base::mac::ScopedMachSendRight scoped_service_port(service_port);
310 331
311 send_rights = 0; 332 send_rights = 0;
312 ASSERT_EQ(KERN_SUCCESS, mach_port_get_refs(task, port, MACH_PORT_RIGHT_SEND, 333 ASSERT_EQ(KERN_SUCCESS, mach_port_get_refs(task, port, MACH_PORT_RIGHT_SEND,
313 &send_rights)); 334 &send_rights));
314 EXPECT_EQ(2u, send_rights); 335 EXPECT_EQ(2u, send_rights);
315 } 336 }
316 337
317 } // namespace sandbox 338 } // namespace sandbox
OLDNEW
« no previous file with comments | « no previous file | sandbox/mac/launchd_interception_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698