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 "sandbox/linux/services/broker_process.h" | 5 #include "sandbox/linux/services/broker_process.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 ASSERT_EQ(0, ret & (O_CLOEXEC | O_NONBLOCK)); | 398 ASSERT_EQ(0, ret & (O_CLOEXEC | O_NONBLOCK)); |
399 ASSERT_EQ(0, close(fd)); | 399 ASSERT_EQ(0, close(fd)); |
400 | 400 |
401 fd = open_broker.Open(kCpuInfo, O_RDONLY | O_CLOEXEC); | 401 fd = open_broker.Open(kCpuInfo, O_RDONLY | O_CLOEXEC); |
402 ASSERT_GE(fd, 0); | 402 ASSERT_GE(fd, 0); |
403 ret = fcntl(fd, F_GETFD); | 403 ret = fcntl(fd, F_GETFD); |
404 ASSERT_NE(-1, ret); | 404 ASSERT_NE(-1, ret); |
405 // Important: use F_GETFD, not F_GETFL. The O_CLOEXEC flag in F_GETFL | 405 // Important: use F_GETFD, not F_GETFL. The O_CLOEXEC flag in F_GETFL |
406 // is actually not used by the kernel. | 406 // is actually not used by the kernel. |
407 ASSERT_TRUE(FD_CLOEXEC & ret); | 407 ASSERT_TRUE(FD_CLOEXEC & ret); |
408 | |
409 // There is buggy userland code that can check for O_CLOEXEC with fcntl(2) | |
410 // even though it doesn't mean anything. We need to support this case. | |
411 // See crbug.com/237283. | |
412 ret = fcntl(fd, F_GETFL); | |
413 ASSERT_NE(-1, ret); | |
414 ASSERT_TRUE(O_CLOEXEC & ret); | |
415 | |
416 ASSERT_EQ(0, close(fd)); | 408 ASSERT_EQ(0, close(fd)); |
417 | 409 |
418 fd = open_broker.Open(kCpuInfo, O_RDONLY | O_NONBLOCK); | 410 fd = open_broker.Open(kCpuInfo, O_RDONLY | O_NONBLOCK); |
419 ASSERT_GE(fd, 0); | 411 ASSERT_GE(fd, 0); |
420 ret = fcntl(fd, F_GETFL); | 412 ret = fcntl(fd, F_GETFL); |
421 ASSERT_NE(-1, ret); | 413 ASSERT_NE(-1, ret); |
422 ASSERT_TRUE(O_NONBLOCK & ret); | 414 ASSERT_TRUE(O_NONBLOCK & ret); |
423 ASSERT_EQ(0, close(fd)); | 415 ASSERT_EQ(0, close(fd)); |
424 } | 416 } |
425 | 417 |
426 TEST(BrokerProcess, OpenComplexFlagsWithClientCheck) { | 418 TEST(BrokerProcess, OpenComplexFlagsWithClientCheck) { |
427 TestOpenComplexFlags(true /* fast_check_in_client */); | 419 TestOpenComplexFlags(true /* fast_check_in_client */); |
428 // Don't do anything here, so that ASSERT works in the subfunction as | 420 // Don't do anything here, so that ASSERT works in the subfunction as |
429 // expected. | 421 // expected. |
430 } | 422 } |
431 | 423 |
432 TEST(BrokerProcess, OpenComplexFlagsNoClientCheck) { | 424 TEST(BrokerProcess, OpenComplexFlagsNoClientCheck) { |
433 TestOpenComplexFlags(false /* fast_check_in_client */); | 425 TestOpenComplexFlags(false /* fast_check_in_client */); |
434 // Don't do anything here, so that ASSERT works in the subfunction as | 426 // Don't do anything here, so that ASSERT works in the subfunction as |
435 // expected. | 427 // expected. |
436 } | 428 } |
437 | 429 |
438 } // namespace sandbox | 430 } // namespace sandbox |
OLD | NEW |