Skip to content

Commit fbbf540

Browse files
committed
intercept: file open with O_TRUNC to avoid corrupt output if the file is already exists.
If the output of intercept is a file that already exists, the file was not trucated. Then if the output length is smaller than previous output, the content is corrupt.
1 parent 0f38e9b commit fbbf540

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

source/intercept/source/collect/db/EventsDatabaseWriter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace {
4848
namespace ic::collect::db {
4949

5050
rust::Result<EventsDatabaseWriter::Ptr> EventsDatabaseWriter::create(const fs::path &file) {
51-
int fd = open(file.c_str(), O_WRONLY | O_CREAT, 00644);
51+
int fd = open(file.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 00644);
5252
if (fd == -1) {
5353
auto message = fmt::format("Events db open failed (file {}): {}", file.string(), sys::error_string(errno));
5454
return rust::Err(std::runtime_error(message));

0 commit comments

Comments
 (0)