diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-04-23 16:50:01 +0300 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-04-23 16:50:01 +0300 |
commit | 54cc702419163c416e5511f487fcb80cb37b2561 (patch) | |
tree | c93ef759f2973bb4149b806ee4da055a749a5222 /subprojects/plugin_hostlist/filterlist.cpp | |
parent | Remove plugin_hostlist:interface (diff) | |
download | smolbote-54cc702419163c416e5511f487fcb80cb37b2561.tar.xz |
plugin_hostlist: add fuzzer
Diffstat (limited to 'subprojects/plugin_hostlist/filterlist.cpp')
-rw-r--r-- | subprojects/plugin_hostlist/filterlist.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/subprojects/plugin_hostlist/filterlist.cpp b/subprojects/plugin_hostlist/filterlist.cpp index 42be349..a0fd414 100644 --- a/subprojects/plugin_hostlist/filterlist.cpp +++ b/subprojects/plugin_hostlist/filterlist.cpp @@ -6,14 +6,26 @@ * SPDX-License-Identifier: GPL-3.0 */ -#include "filterlist.hpp" +#include "filterlist.h" #include <QIODevice> #include <QTextStream> using namespace Hostlist; +#ifdef FUZZER +extern "C" int LLVMFuzzerTestOneInput(const char *Data, long long Size) +{ + Filterlist::parseRule(QString::fromLatin1(Data, Size)); + return 0; +} +#endif + std::map<Filterlist::DomainHash, Filterlist::Rule> Filterlist::parseRule(const QString &line) { + if(line.isEmpty() || line.at(0) == '#') { + return {}; + } + auto parts = line.trimmed().split(' '); if(parts.size() < 2) { return {}; @@ -36,14 +48,11 @@ bool Filterlist::load(QIODevice &from) while(from.bytesAvailable() > 0) { const auto line = from.readLine(512).trimmed(); - if(!line.isEmpty() && line.at(0) != '#') { - auto r = parseRule(line); - if(!r.empty()) { - qDebug("merging in %lu rules", r.size()); - rules.merge(r); - } + auto r = parseRule(line); + if(!r.empty()) { + qDebug("merging in %lu rules", r.size()); + rules.merge(r); } } return true; } - |