From: Michael Hanselmann Date: Wed, 3 Apr 2019 23:10:11 +0000 (+0200) Subject: Add fuzzing binary for oLschema2ldif X-Git-Tag: tdb-1.4.2~275 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=39e2f6d59fa2e839c8ef40934790b34dbdfc8f29;p=thirdparty%2Fsamba.git Add fuzzing binary for oLschema2ldif Use the oLschema2ldif library functions introduced in commit 0c7c44a284a26790081c000f5b8f4ed32f9f21d7 to implement a fuzzing utility. Signed-off-by: Michael Hanselmann Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- diff --git a/lib/fuzzing/fuzz_oLschema2ldif.c b/lib/fuzzing/fuzz_oLschema2ldif.c new file mode 100644 index 00000000000..4dd5668e673 --- /dev/null +++ b/lib/fuzzing/fuzz_oLschema2ldif.c @@ -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 . +*/ + +#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; +} diff --git a/lib/fuzzing/wscript_build b/lib/fuzzing/wscript_build index 3db2a8b825a..9c73c59c259 100644 --- a/lib/fuzzing/wscript_build +++ b/lib/fuzzing/wscript_build @@ -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, + )