[file_utils] Check the file type to prevent unexpected writes by thin_repair
This commit is contained in:
parent
87ada9b493
commit
6cecf0f673
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user