Skip to content

Commit

Permalink
fix(sanitizer): fix heap-use-after free in hdfs client test (#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
levy5307 authored Jul 30, 2021
1 parent a530ef4 commit 3bda0ba
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/block_service/test/hdfs_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class HDFSClientTest : public testing::Test
virtual void SetUp() override;
virtual void TearDown() override;
void generate_test_file(const char *filename);
void write_test_files_async();
void write_test_files_async(task_tracker *tracker);
std::string name_node;
std::string backup_path;
std::string local_test_dir;
Expand Down Expand Up @@ -83,11 +83,11 @@ void HDFSClientTest::generate_test_file(const char *filename)
fclose(fp);
}

void HDFSClientTest::write_test_files_async()
void HDFSClientTest::write_test_files_async(task_tracker *tracker)
{
dsn::utils::filesystem::create_directory(local_test_dir);
for (int i = 0; i < 100; ++i) {
tasking::enqueue(LPC_TEST_HDFS, nullptr, [this, i]() {
tasking::enqueue(LPC_TEST_HDFS, tracker, [this, i]() {
// mock the writing process in hdfs_file_object::download().
std::string test_file_name = local_test_dir + "/test_file_" + std::to_string(i);
std::ofstream out(test_file_name, std::ios::binary | std::ios::out | std::ios::trunc);
Expand Down Expand Up @@ -368,17 +368,21 @@ TEST_F(HDFSClientTest, test_concurrent_upload_download)

TEST_F(HDFSClientTest, test_rename_path_while_writing)
{
write_test_files_async();
task_tracker tracker;
write_test_files_async(&tracker);
usleep(100);
std::string rename_dir = "rename_dir." + std::to_string(dsn_now_ms());
// rename succeed but writing failed.
ASSERT_TRUE(dsn::utils::filesystem::rename_path(local_test_dir, rename_dir));
tracker.cancel_outstanding_tasks();
}

TEST_F(HDFSClientTest, test_remove_path_while_writing)
{
write_test_files_async();
task_tracker tracker;
write_test_files_async(&tracker);
usleep(100);
// couldn't remove the directory while writing files in it.
ASSERT_FALSE(dsn::utils::filesystem::remove_path(local_test_dir));
tracker.cancel_outstanding_tasks();
}

0 comments on commit 3bda0ba

Please sign in to comment.