aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/plugin_constructors.py
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2017-05-23 18:33:00 +0200
committerTobias Brunner <tobias@strongswan.org>2017-05-23 18:38:46 +0200
commit4cc77142e0292d5d00f20e62849139f4401895c8 (patch)
treed19d858f3f27791781a879703951b9218f0c179f /src/libstrongswan/plugins/plugin_constructors.py
parent4d0795bcefeb7d6156fda9b59e75a7dbe05de6e5 (diff)
parenta9b698f5be2519353d91cd6be52b97ce7f5d6fe6 (diff)
downloadstrongswan-4cc77142e0292d5d00f20e62849139f4401895c8.tar.bz2
strongswan-4cc77142e0292d5d00f20e62849139f4401895c8.tar.xz
Merge branch 'fuzzing'
Adds support for fuzzing the certificate parser provided by the default plugins (x509, pem, gmp etc.) on Google's OSS-Fuzz infrastructure (or generally with libFuzzer). Fixes several issues that were found while fuzzing these plugins. When building the libraries monolithically and statically the plugin constructors are now hard-coded in each library so the plugin code is not removed by the linker because it thinks none of their symbols are ever referenced.
Diffstat (limited to 'src/libstrongswan/plugins/plugin_constructors.py')
-rw-r--r--src/libstrongswan/plugins/plugin_constructors.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/libstrongswan/plugins/plugin_constructors.py b/src/libstrongswan/plugins/plugin_constructors.py
new file mode 100644
index 000000000..d9c40e383
--- /dev/null
+++ b/src/libstrongswan/plugins/plugin_constructors.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2017 Tobias Brunner
+# HSR Hochschule fuer Technik Rapperswil
+#
+# 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 (at your
+# option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+#
+# 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.
+
+import sys
+from argparse import ArgumentParser
+
+def generate_output(plugins):
+ """Generate a source file containing plugin constructor registrations"""
+ print("/**")
+ print(" * Register plugin constructors for static libraries")
+ print(" * Created by {0}".format(__file__))
+ print(" */")
+ print("")
+ print("#include <plugins/plugin.h>")
+ print("#include <plugins/plugin_loader.h>")
+ print("")
+
+ for plugin in plugins:
+ print("plugin_t *{0}_plugin_create();".format(plugin.replace('-', '_')))
+
+ print("")
+ print("static void register_plugins() __attribute__ ((constructor));")
+ print("static void register_plugins()")
+ print("{")
+
+ for plugin in plugins:
+ print(' plugin_constructor_register("{0}", {1}_plugin_create);'.format(plugin, plugin.replace('-', '_')))
+
+ print("}")
+
+ print("")
+ print("static void unregister_plugins() __attribute__ ((destructor));")
+ print("static void unregister_plugins()")
+ print("{")
+
+ for plugin in plugins:
+ print(' plugin_constructor_register("{0}", NULL);'.format(plugin))
+
+ print("}")
+ print("")
+
+parser = ArgumentParser(description = "Generate constructor registration for a list of plugins")
+parser.add_argument('plugins', metavar="plugin", nargs="*",
+ help = "name of a plugin for which to generate constructor registration")
+
+
+args = parser.parse_args()
+generate_output(args.plugins);