[file_utils] Check the file type to prevent unexpected writes by thin_repair

This commit is contained in:
Ming-Hung Tsai 2021-07-08 01:15:28 +08:00
parent 87ada9b493
commit 6cecf0f673
2 changed files with 7 additions and 2 deletions

View File

@ -77,8 +77,12 @@ file_utils::check_file_exists(string const &file, bool must_be_regular_file) {
throw runtime_error(msg.str());
}
if (must_be_regular_file && !S_ISREG(info.st_mode))
throw runtime_error("Not a regular file");
if (!S_ISREG(info.st_mode)) {
if (must_be_regular_file)
throw runtime_error("Not a regular file");
if (!S_ISBLK(info.st_mode))
throw runtime_error("Not a block device or regular file");
}
}
file_utils::file_descriptor

View File

@ -81,6 +81,7 @@ test_accepts_version!(ThinRepair);
test_rejects_bad_option!(ThinRepair);
test_input_file_not_found!(ThinRepair);
test_input_cannot_be_a_directory!(ThinRepair);
test_corrupted_input_data!(ThinRepair);
test_missing_output_option!(ThinRepair);