summaryrefslogtreecommitdiff
path: root/modules/commands/os_logsearch.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2016-11-22 19:35:11 -0500
committerAdam <Adam@anope.org>2016-11-22 19:35:11 -0500
commitd96ca9b8240bcd854995946bdddc46632acc658a (patch)
tree57dbdee439b1ba7604b516a6bbf5a83b7581c513 /modules/commands/os_logsearch.cpp
parent23a0628fba15be8bae73c8413e406780427fe60c (diff)
os_logsearch: add a hard max limit and make the limiter smarter
Diffstat (limited to 'modules/commands/os_logsearch.cpp')
-rw-r--r--modules/commands/os_logsearch.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/modules/commands/os_logsearch.cpp b/modules/commands/os_logsearch.cpp
index f8ee99d4e..37a2f887c 100644
--- a/modules/commands/os_logsearch.cpp
+++ b/modules/commands/os_logsearch.cpp
@@ -11,6 +11,8 @@
#include "module.h"
+static unsigned int HARDMAX = 65536;
+
class CommandOSLogSearch : public Command
{
static inline Anope::string CreateLogName(const Anope::string &file, time_t t = Anope::CurTime)
@@ -90,7 +92,7 @@ class CommandOSLogSearch : public Command
Log(LOG_ADMIN, source, this) << "for " << search_string;
const Anope::string &logfile_name = Config->GetModule(this->owner)->Get<const Anope::string>("logname");
- std::list<Anope::string> matches;
+ std::vector<Anope::string> matches;
for (int d = days - 1; d >= 0; --d)
{
Anope::string lf_name = CreateLogName(logfile_name, Anope::CurTime - (d * 86400));
@@ -101,24 +103,37 @@ class CommandOSLogSearch : public Command
for (Anope::string buf, token; std::getline(fd, buf.str());)
if (Anope::Match(buf, "*" + search_string + "*"))
+ {
matches.push_back(buf);
+ if (matches.size() >= HARDMAX)
+ break;
+ }
+
fd.close();
}
- unsigned found = matches.size();
+ unsigned int found = matches.size();
if (!found)
{
source.Reply(_("No matches for \002%s\002 found."), search_string.c_str());
return;
}
- while (matches.size() > static_cast<unsigned>(replies))
- matches.pop_front();
+ if (matches.size() >= HARDMAX)
+ {
+ source.Reply(_("Too many results for \002%s\002."), search_string.c_str());
+ return;
+ }
+
+ if (matches.size() > static_cast<unsigned int>(replies))
+ {
+ matches.erase(matches.begin(), matches.begin() + (matches.size() - static_cast<unsigned int>(replies)));
+ }
source.Reply(_("Matches for \002%s\002:"), search_string.c_str());
- unsigned count = 0;
- for (std::list<Anope::string>::iterator it = matches.begin(), it_end = matches.end(); it != it_end; ++it)
+ unsigned int count = 0;
+ for (std::vector<Anope::string>::iterator it = matches.begin(), it_end = matches.end(); it != it_end; ++it)
source.Reply("#%d: %s", ++count, it->c_str());
source.Reply(_("Showed %d/%d matches for \002%s\002."), matches.size(), found, search_string.c_str());
}