Skip to content

Commit b0a5694

Browse files
committed
This code fixes the errors from owasp-modsecurity#2304
Signed-off-by: Kasumi <kasumi@kitsune.exposed>
1 parent 7da14cc commit b0a5694

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/audit_log/writer/parallel.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Parallel : public Writer {
4040
bool init(std::string *error) override;
4141
bool write(Transaction *transaction, int parts,
4242
std::string *error) override;
43+
bool reopen(std::string *error) override;
4344

4445

4546
/**

src/rules_set.cc

+19
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,25 @@ extern "C" void msc_rules_error_cleanup(const char *error) {
325325
free((void*) error);
326326
}
327327

328+
extern "C" int msc_rules_reopen_audit_log(RulesSet *rules, const char **error) {
329+
bool succeeded = true;
330+
std::string errorStr;
331+
332+
if (rules->m_auditLog != NULL) {
333+
succeeded = rules->m_auditLog->reopen(&errorStr);
334+
}
335+
336+
if (!succeeded) {
337+
if (!errorStr.empty()) {
338+
*error = strdup(errorStr.c_str());
339+
} else {
340+
// Guarantee an error message is always assigned in the event of a failure
341+
*error = strdup("Unknown error reopening audit log");
342+
}
343+
}
344+
345+
return succeeded ? 0 : -1;
346+
}
328347

329348
extern "C" int msc_rules_cleanup(RulesSet *rules) {
330349
delete rules;

src/utils/shared_files.cc

+18-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
#include "src/utils/shared_files.h"
17-
17+
#include <cstring>
1818
#include <fcntl.h>
1919
#ifdef WIN32
2020
#include <algorithm>
@@ -101,6 +101,23 @@ void SharedFiles::close(const std::string& fileName) {
101101
}
102102
}
103103

104+
bool SharedFiles::reopen(const std::string& fileName, std::string *error) {
105+
auto it = m_handlers.find(fileName);
106+
if (it == m_handlers.end()) {
107+
return open(fileName, error);
108+
}
109+
110+
FILE* new_fp = fopen(fileName.c_str(), "a+");
111+
if (new_fp == nullptr) {
112+
error->assign("Failed to reopen file: " + fileName + " - " + strerror(errno));
113+
return false;
114+
}
115+
116+
fclose(it->second.fp);
117+
it->second.fp = new_fp;
118+
119+
return true;
120+
}
104121

105122
bool SharedFiles::write(const std::string& fileName,
106123
const std::string &msg, std::string *error) {

0 commit comments

Comments
 (0)