diff options
author | maclellant <maclellant@google.com> | 2015-11-20 15:21:46 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-20 23:22:31 +0000 |
commit | 912064d3478c083d4f8030376673018e3e6a2d60 (patch) | |
tree | 6989febb36ac224f99330916a66792f2f9ed536e /net/dns/dns_config_service_posix_unittest.cc | |
parent | beef274074ec525b2fb5ad3de3f205fdfc3df6e9 (diff) | |
download | chromium_src-912064d3478c083d4f8030376673018e3e6a2d60.zip chromium_src-912064d3478c083d4f8030376673018e3e6a2d60.tar.gz chromium_src-912064d3478c083d4f8030376673018e3e6a2d60.tar.bz2 |
Fix SerialWorker crash accessing DnsConfigServicePosix pointer.
DnsConfigServicePosix is creating two SerialWorker instances that
run jobs on worker thread, however, these workers hold a raw pointer
to the service instance and access the pointer on the worker thread
to check testing values. When the instance is destroyed before the
serial workers finish a crash occurs.
This fix is to never access the raw pointer from the worker thread,
instead binding the serial worker to a given mock value for testing.
If the value changes the worker is canceled and recreated.
BUG=558788
Review URL: https://codereview.chromium.org/1447163008
Cr-Commit-Position: refs/heads/master@{#360945}
Diffstat (limited to 'net/dns/dns_config_service_posix_unittest.cc')
-rw-r--r-- | net/dns/dns_config_service_posix_unittest.cc | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/net/dns/dns_config_service_posix_unittest.cc b/net/dns/dns_config_service_posix_unittest.cc index 4d2acdd..03a1391 100644 --- a/net/dns/dns_config_service_posix_unittest.cc +++ b/net/dns/dns_config_service_posix_unittest.cc @@ -41,6 +41,10 @@ const char* const kNameserversIPv6[] = { }; #endif +void DummyConfigCallback(const DnsConfig& config) { + // Do nothing +} + // Fills in |res| with sane configuration. void InitializeResState(res_state res) { memset(res, 0, sizeof(*res)); @@ -164,6 +168,16 @@ TEST(DnsConfigServicePosixTest, RejectEmptyNameserver) { internal::ConvertResStateToDnsConfig(res, &config)); } +TEST(DnsConfigServicePosixTest, DestroyWhileJobsWorking) { + // Regression test to verify crash does not occur if DnsConfigServicePosix + // instance is destroyed while SerialWorker jobs have posted to worker pool. + scoped_ptr<internal::DnsConfigServicePosix> service( + new internal::DnsConfigServicePosix()); + service->ReadConfig(base::Bind(&DummyConfigCallback)); + service.reset(); + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1000)); +} + } // namespace #else // OS_ANDROID @@ -198,6 +212,10 @@ class DnsConfigServicePosixTest : public testing::Test { service_->SetDnsConfigForTesting(&test_config_); } + void MockHostsFilePath(const char* file_path) { + service_->SetHostsFilePathForTesting(file_path); + } + void SetUp() override { // TODO(pauljensen): Get rid of GetExternalStorageDirectory() when // crbug.com/475568 is fixed. For now creating a temp file in the @@ -226,7 +244,7 @@ class DnsConfigServicePosixTest : public testing::Test { void StartWatching() { creation_time_ = base::Time::Now(); service_.reset(new DnsConfigServicePosix()); - service_->file_path_hosts_ = temp_file_.value().c_str(); + MockHostsFilePath(temp_file_.value().c_str()); MockDNSConfig("8.8.8.8"); seen_config_ = false; service_->WatchConfig(base::Bind( |