From 4f38f0f1e1065514c23064b2b8a84ab334aa8415 Mon Sep 17 00:00:00 2001 From: project-repo Date: Thu, 13 Apr 2023 18:40:54 +0200 Subject: [PATCH] Add fuzzing script --- README.md | 16 ++++++++++++++++ meson.build | 3 +++ meson_options.txt | 1 + scripts/fuzz | 16 ++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100755 scripts/fuzz diff --git a/README.md b/README.md index a194d55..03a0fc2 100644 --- a/README.md +++ b/README.md @@ -278,6 +278,22 @@ if meson is already available or otherwise. +#### Scripts + +Cagebreak provides a few convenience tools to facilitate development. + +##### Fuzzing + +If your fuzzing corpus is located in the directory `fuzz_corpus` you can +just call: + +``` +meson compile fuzz -C build +``` + +If you want to use a different directory, configure cagebreak with +`-Dcorpus=OTHERDIRECTORY` or call `./scripts/fuzz OTHERDIRECTORY`. + ### GCC and -fanalyzer Cagebreak should compile with any reasonably new gcc or clang. Consider diff --git a/meson.build b/meson.build index e9388c2..f43de32 100644 --- a/meson.build +++ b/meson.build @@ -347,6 +347,9 @@ message('\n'.join(summary)) run_target('devel-install', command : ['scripts/install-development-environment']) +run_target('fuzz', + command : ['scripts/fuzz', get_option('corpus')]) + # Test Suite test('Build without warnings', find_program('test/build-w-o-warnings'), env : [ ''.join('MESONCURRENTCONFIGDIR=', meson.current_source_dir()) ], suite: 'devel') diff --git a/meson_options.txt b/meson_options.txt index b7fc956..df62d70 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -4,3 +4,4 @@ option('xwayland', type: 'boolean', value: 'false', description: 'Enable support option('man-pages', type: 'boolean', value: 'false', description: 'Build man pages (requires pandoc)') option('fuzz', type: 'boolean', value: 'false', description: 'Enable building fuzzer targets') option('version_override', type: 'string', description: 'Set the project version to the string specified. Used for creating hashes for reproducible builds.') +option('corpus', type: 'string', value: 'fuzz_corpus', description: 'Set fuzzing corpus directory') diff --git a/scripts/fuzz b/scripts/fuzz new file mode 100755 index 0000000..8792016 --- /dev/null +++ b/scripts/fuzz @@ -0,0 +1,16 @@ +#!/bin/bash +# Copyright 2023, project-repo and the cagebreak contributors +# SPDX-License-Identifier: MIT + +readonly fuzzing_corpus="${1}" + +if [[ -n ${MESON_SOURCE_ROOT} ]] +then + # shellcheck disable=2164 + cd "${MESON_SOURCE_ROOT}" +fi + +rm -rf fuzzing-directory +CC=clang meson setup fuzzing-directory -Dfuzz=true -Db_sanitize=address,undefined -Db_lundef=false -Db_detect-leaks=0 +ninja -C fuzzing-directory/ +WLR_BACKENDS=headless ./fuzzing-directory/fuzz-parse -jobs=12 -max_len=50000 -close_fd_mask=3 "${fuzzing_corpus}"