From 90d28f0519427ffc293f880c423d9c4395a6fcd4 Mon Sep 17 00:00:00 2001 From: Ben Laurie Date: Sat, 4 Jun 2016 16:10:49 +0100 Subject: Run the fuzzing corpora as tests. Reviewed-by: Richard Levitte Reviewed-by: Rich Salz --- test/recipes/05-test_fuzz.t | 33 +++++++++++++++++++++++++++++++++ test/testlib/OpenSSL/Test.pm | 21 ++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 test/recipes/05-test_fuzz.t (limited to 'test') diff --git a/test/recipes/05-test_fuzz.t b/test/recipes/05-test_fuzz.t new file mode 100755 index 0000000000..f5ae228de4 --- /dev/null +++ b/test/recipes/05-test_fuzz.t @@ -0,0 +1,33 @@ +#!/usr/bin/env perl +# Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the OpenSSL license (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + +use strict; +use warnings; + +use if $^O ne "VMS", 'File::Glob' => qw/glob/; +use OpenSSL::Test qw/:DEFAULT srctop_file/; + +setup("test_fuzz"); + +my @fuzzers = ('asn1', 'asn1parse', 'bignum', 'bndiv', 'cms', 'conf', 'ct', 'server'); +plan tests => scalar @fuzzers; + +foreach my $f (@fuzzers) { + subtest "Fuzzing $f" => sub { + my @files = glob(srctop_file('fuzz', 'corpora', $f, '*')); + push @files, glob(srctop_file('fuzz', 'corpora', "$f-*", '*')); + + plan skip_all => "No corpora for $f-test" unless @files; + + plan tests => scalar @files; + + foreach (@files) { + ok(run(fuzz(["$f-test", $_]))); + } + } +} diff --git a/test/testlib/OpenSSL/Test.pm b/test/testlib/OpenSSL/Test.pm index 31f41057f0..0c3b9104e9 100644 --- a/test/testlib/OpenSSL/Test.pm +++ b/test/testlib/OpenSSL/Test.pm @@ -16,7 +16,8 @@ use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = "0.8"; @ISA = qw(Exporter); -@EXPORT = (@Test::More::EXPORT, qw(setup indir app perlapp test perltest run)); +@EXPORT = (@Test::More::EXPORT, qw(setup indir app fuzz perlapp test perltest + run)); @EXPORT_OK = (@Test::More::EXPORT_OK, qw(bldtop_dir bldtop_file srctop_dir srctop_file pipe with cmdstr quotify)); @@ -285,6 +286,13 @@ sub app { return __build_cmd($num, \&__apps_file, $cmd, %opts); } } +sub fuzz { + my $cmd = shift; + my %opts = @_; + return sub { my $num = shift; + return __build_cmd($num, \&__fuzz_file, $cmd, %opts); } +} + sub test { my $cmd = shift; my %opts = @_; @@ -701,6 +709,8 @@ sub __env { $directories{BLDTOP} = $ENV{BLDTOP} || $ENV{TOP}; $directories{BLDAPPS} = $ENV{BIN_D} || __bldtop_dir("apps"); $directories{SRCAPPS} = __srctop_dir("apps"); + $directories{BLDFUZZ} = __bldtop_dir("fuzz"); + $directories{SRCFUZZ} = __srctop_dir("fuzz"); $directories{BLDTEST} = $ENV{TEST_D} || __bldtop_dir("test"); $directories{SRCTEST} = __srctop_dir("test"); $directories{RESULTS} = $ENV{RESULT_D} || $directories{BLDTEST}; @@ -778,6 +788,15 @@ sub __apps_file { return $f; } +sub __fuzz_file { + BAIL_OUT("Must run setup() first") if (! $test_name); + + my $f = pop; + $f = catfile($directories{BLDFUZZ},@_,$f . __exeext()); + $f = catfile($directories{SRCFUZZ},@_,$f) unless -x $f; + return $f; +} + sub __perlapps_file { BAIL_OUT("Must run setup() first") if (! $test_name); -- cgit v1.2.3