Skip to content

Commit f3a5ac2

Browse files
committed
MB-32840: Prevent crash when rotating empty audit log
BP of MB-32231: http://review.couchbase.org/#/c/102432/ Change-Id: I5db72afaca6bc627a618d1cbbdbc6ae5173d3810 Reviewed-on: http://review.couchbase.org/104202 Well-Formed: Build Bot <[email protected]> Tested-by: Build Bot <[email protected]> Reviewed-by: Dave Rigby <[email protected]>
1 parent cae94e3 commit f3a5ac2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

auditd/src/auditfile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class AuditFile {
5353
// closing and then re-opening we can just keep open and
5454
// update the open_time.
5555
open_time = auditd_time();
56-
return true;
56+
return false;
5757
}
5858
close_and_rotate_log();
5959
return true;

auditd/tests/auditfile_test.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,28 @@ TEST_F(AuditFileTest, TestFileCreation) {
8282
EXPECT_EQ(1, files.size());
8383
}
8484

85+
/**
86+
* Test that an empty file is properly rotated using ensure_open()
87+
* Seen issues in the past such as MB-32232
88+
*/
89+
TEST_F(AuditFileTest, TestRotateEmptyFile) {
90+
AuditConfig defaultvalue;
91+
config.set_rotate_interval(defaultvalue.get_min_file_rotation_time());
92+
config.set_rotate_size(1024*1024);
93+
94+
AuditFile auditfile;
95+
auditfile.reconfigure(config);
96+
97+
auditfile.ensure_open();
98+
cb_timeofday_timetravel(defaultvalue.get_min_file_rotation_time() + 1);
99+
auditfile.ensure_open();
100+
101+
auditfile.close();
102+
103+
auto files = findFilesWithPrefix(testdir + "/testing");
104+
EXPECT_EQ(0, files.size());
105+
}
106+
85107
/**
86108
* Test that we can create a file, and as time flies by we rotate
87109
* to use the next file

0 commit comments

Comments
 (0)