diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2017-07-30 01:45:22 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2017-08-03 07:26:53 +0200 |
commit | ba101a1aeb88d6cfbae6f8e81cc104bae0c6c9fe (patch) | |
tree | d4216da8ce41cfd3af1c1bd8aa358ec832390cfd /devel | |
parent | a087b6334c53f69adf44aa58f2728dd592f4080c (diff) | |
download | gnutls-ba101a1aeb88d6cfbae6f8e81cc104bae0c6c9fe.tar.gz |
fuzz: ported libidn2's main.c taking advantage of afl-clang-fast
Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
Diffstat (limited to 'devel')
-rw-r--r-- | devel/fuzz/main.c | 58 | ||||
-rwxr-xr-x | devel/fuzz/run-afl.sh | 15 |
2 files changed, 51 insertions, 22 deletions
diff --git a/devel/fuzz/main.c b/devel/fuzz/main.c index 602943014c..217b2e3df9 100644 --- a/devel/fuzz/main.c +++ b/devel/fuzz/main.c @@ -1,22 +1,24 @@ /* * Copyright (C) 2017 Nikos Mavrogiannopoulos + * Copyright (C) 2017 Tim Ruehsen * - * Author: Nikos Mavrogiannopoulos + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * This file is part of GnuTLS. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * The GnuTLS is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * */ @@ -31,14 +33,34 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); +#ifndef __AFL_LOOP +static int __AFL_LOOP(int n) +{ + static int first = 1; + + if (first) { + first = 0; + return 1; + } + + return 0; +} +#endif + int main(int argc, char **argv) { int ret; unsigned char buf[64*1024]; - ret = fread(buf, 1, sizeof(buf), stdin); - if (ret <= 0) - return 0; + while (__AFL_LOOP(10000)) { // only works with afl-clang-fast + ret = fread(buf, 1, sizeof(buf), stdin); + if (ret <= 0) + return 0; + + ret = LLVMFuzzerTestOneInput(buf, ret); + if (ret != 0) + return ret; + } - return LLVMFuzzerTestOneInput(buf, ret); + return 0; } diff --git a/devel/fuzz/run-afl.sh b/devel/fuzz/run-afl.sh index 95c6c43099..fcb4f35b52 100755 --- a/devel/fuzz/run-afl.sh +++ b/devel/fuzz/run-afl.sh @@ -21,9 +21,16 @@ export LD_LIBRARY_PATH=${srcdir}/../../lib/.libs/ cat ${srcdir}/../../config.log|grep afl-gcc >/dev/null 2>&1 if test $? != 0;then - echo "compile first library as:" - echo "CC=afl-gcc ./configure" - exit 1 + cat ${srcdir}/../../config.log|grep afl-clang-fast >/dev/null 2>&1 + if test $? != 0;then + echo "compile first library as:" + echo "CC=afl-gcc ./configure" + exit 1 + else + fuzz=afl-clang-fast + fi +else + fuzz=afl-gcc fi if test -z "$1";then @@ -33,7 +40,7 @@ if test -z "$1";then fi rm -f $1 -CFLAGS="-g -O2" CC=afl-gcc make $1 || exit 1 +CFLAGS="-g -O2" CC=${fuzz} make $1 || exit 1 TEST=$(echo $1|sed s/_fuzzer//) |