Add fuzzing binary for oLschema2ldif
authorMichael Hanselmann <public@hansmi.ch>
Wed, 3 Apr 2019 23:10:11 +0000 (01:10 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 7 Aug 2019 06:07:28 +0000 (06:07 +0000)
Use the oLschema2ldif library functions introduced in commit
0c7c44a284a26790081c000f5b8f4ed32f9f21d7 to implement a fuzzing utility.

Signed-off-by: Michael Hanselmann <public@hansmi.ch>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
lib/fuzzing/fuzz_oLschema2ldif.c [new file with mode: 0644]
lib/fuzzing/wscript_build

diff --git a/lib/fuzzing/fuzz_oLschema2ldif.c b/lib/fuzzing/fuzz_oLschema2ldif.c
new file mode 100644 (file)
index 0000000..4dd5668
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+   Fuzzing for oLschema2ldif
+   Copyright (C) Michael Hanselmann 2019
+
+   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 3 of the License, or
+   (at your option) 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 "includes.h"
+#include "fuzzing.h"
+#include "utils/oLschema2ldif/lib.h"
+
+static FILE *devnull;
+
+int LLVMFuzzerInitialize(int *argc, char ***argv)
+{
+       devnull = fopen("/dev/null", "w");
+
+       return 0;
+}
+
+int LLVMFuzzerTestOneInput(uint8_t *buf, size_t len)
+{
+       TALLOC_CTX *mem_ctx;
+       struct conv_options opt;
+
+       mem_ctx = talloc_init(__FUNCTION__);
+
+       opt.in = fmemopen(buf, len, "r");
+       opt.out = devnull;
+       opt.ldb_ctx = ldb_init(mem_ctx, NULL);
+
+       opt.basedn = ldb_dn_new(mem_ctx, opt.ldb_ctx, "");
+
+       process_file(mem_ctx, &opt);
+
+       fclose(opt.in);
+
+       talloc_free(mem_ctx);
+
+       return 0;
+}
index 3db2a8b825a5bdc32f7b0a51d400d498c8798977..9c73c59c25969f3846f52b83c1c55e21a8cbaa9d 100644 (file)
@@ -11,3 +11,10 @@ bld.SAMBA_BINARY('fuzz_tiniparser',
                  deps='fuzzing tiniparser talloc',
                  install=False,
                  enabled=bld.env.enable_libfuzzer)
+
+bld.SAMBA_BINARY('fuzz_oLschema2ldif',
+                 source='fuzz_oLschema2ldif.c',
+                 deps='fuzzing oLschema2ldif-lib',
+                 install=False,
+                 enabled=bld.env.enable_libfuzzer,
+                 )