summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-08-28 14:43:16 +0300
committerAndrei Karas <akaras@inbox.ru>2013-08-29 00:18:56 +0300
commit482cbfc4e1299434a6f632fe7f4b4e3704e65e87 (patch)
treea629b12b8a768f8431de0c134990bdbaf98912b3
parent72cc5d13430dff4e41c77482eebd9e5e421fe739 (diff)
downloadManaVerse-482cbfc4e1299434a6f632fe7f4b4e3704e65e87.tar.gz
ManaVerse-482cbfc4e1299434a6f632fe7f4b4e3704e65e87.tar.bz2
ManaVerse-482cbfc4e1299434a6f632fe7f4b4e3704e65e87.tar.xz
ManaVerse-482cbfc4e1299434a6f632fe7f4b4e3704e65e87.zip
add file access fuzzer.
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/client.cpp5
-rw-r--r--src/localconsts.h3
-rw-r--r--src/utils/fuzzer.cpp58
-rw-r--r--src/utils/fuzzer.h34
-rw-r--r--src/utils/physfsrwops.cpp8
-rw-r--r--src/utils/xml.cpp6
8 files changed, 117 insertions, 1 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 40c7bf942..bf54c4cab 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -522,6 +522,8 @@ SET(SRCS
utils/cpu.cpp
utils/cpu.h
utils/dtor.h
+ utils/fuzzer.cpp
+ utils/fuzzer.h
utils/gettext.h
utils/langs.cpp
utils/langs.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 3d7240abb..a886be801 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -531,6 +531,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
utils/cpu.cpp \
utils/cpu.h \
utils/dtor.h \
+ utils/fuzzer.cpp \
+ utils/fuzzer.h \
utils/gettext.h \
utils/langs.cpp \
utils/langs.h \
diff --git a/src/client.cpp b/src/client.cpp
index a4d77298d..974853279 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -103,6 +103,7 @@
#include "resources/resourcemanager.h"
#include "utils/cpu.h"
+#include "utils/fuzzer.h"
#include "utils/gettext.h"
#include "utils/mkdir.h"
#include "utils/paths.h"
@@ -361,6 +362,10 @@ void Client::gameInit()
else
logger->setLogFile(mLocalDataDir + "/manaplus.log");
+#ifdef USE_FUZZER
+ Fuzzer::init();
+#endif
+
initConfiguration();
paths.setDefaultValues(getPathsDefaults());
initFeatures();
diff --git a/src/localconsts.h b/src/localconsts.h
index d5ae0a904..9eb34c328 100644
--- a/src/localconsts.h
+++ b/src/localconsts.h
@@ -87,4 +87,7 @@
// debug SDL surfaces
// #define DEBUG_SDL_SURFACES 1
+// use file access fuzzer
+// #define USE_FUZZER 1
+
#include "utils/perfomance.h"
diff --git a/src/utils/fuzzer.cpp b/src/utils/fuzzer.cpp
new file mode 100644
index 000000000..4342899c3
--- /dev/null
+++ b/src/utils/fuzzer.cpp
@@ -0,0 +1,58 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "utils/fuzzer.h"
+
+#ifdef USE_FUZZER
+
+#include "client.h"
+#include "logger.h"
+
+#include "utils/stringutils.h"
+
+#include "debug.h"
+
+namespace
+{
+ Logger *fuzz = nullptr;
+ int fuzzRand = 50;
+} // namespace
+
+void Fuzzer::init()
+{
+ fuzz = new Logger;
+ fuzz->setLogFile(client->getLocalDataDirectory() + "/fuzzer.log");
+ unsigned int sr = time(nullptr);
+ fuzz->log("Srand: %u", sr);
+ srand(sr);
+}
+
+bool Fuzzer::conditionTerminate(const char *const name)
+{
+ if ((rand() % 100) <= fuzzRand)
+ {
+ fuzz->log("deleted: %s", name);
+ return true;
+ }
+ fuzz->log("passed: %s", name);
+ return false;
+}
+
+#endif
diff --git a/src/utils/fuzzer.h b/src/utils/fuzzer.h
new file mode 100644
index 000000000..91193901d
--- /dev/null
+++ b/src/utils/fuzzer.h
@@ -0,0 +1,34 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UTILS_FUZZER_H
+#define UTILS_FUZZER_H
+
+#include "localconsts.h"
+
+#ifdef USE_FUZZER
+namespace Fuzzer
+{
+ void init();
+ bool conditionTerminate(const char *const name);
+} // namespace Fuzzer
+
+#endif // USE_FUZZER
+#endif // UTILS_FUZZER_H
diff --git a/src/utils/physfsrwops.cpp b/src/utils/physfsrwops.cpp
index 8216e3794..31b86058c 100644
--- a/src/utils/physfsrwops.cpp
+++ b/src/utils/physfsrwops.cpp
@@ -24,7 +24,9 @@
#include "utils/physfsrwops.h"
-#include <stdio.h> /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */
+#include "utils/fuzzer.h"
+
+#include <stdio.h>
#include "debug.h"
@@ -215,6 +217,10 @@ SDL_RWops *PHYSFSRWOPS_openRead(const char *const fname)
if (!checkFilePath(fname))
return nullptr;
#endif
+#ifdef USE_FUZZER
+ if (Fuzzer::conditionTerminate(fname))
+ return nullptr;
+#endif
return create_rwops(PhysFs::openRead(fname));
} /* PHYSFSRWOPS_openRead */
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index 8e0b03e1e..d19c466d1 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -26,6 +26,8 @@
#include "resources/resourcemanager.h"
+#include "utils/fuzzer.h"
+
#include "utils/translation/podict.h"
#include <iostream>
@@ -44,6 +46,10 @@ namespace XML
Document::Document(const std::string &filename, const bool useResman) :
mDoc(nullptr)
{
+#ifdef USE_FUZZER
+ if (Fuzzer::conditionTerminate(filename.c_str()))
+ return;
+#endif
int size = 0;
char *data = nullptr;
if (useResman)