2021-01-27 16:16:16 +00:00
|
|
|
#!/bin/bash -eu
|
|
|
|
# Copyright 2021 Google LLC
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
2021-02-02 23:59:02 +00:00
|
|
|
# Debugging
|
|
|
|
env
|
|
|
|
|
2021-02-15 17:40:12 +00:00
|
|
|
# Some of the sanitizer flags cause issues with configure tests.
|
|
|
|
# Pull them out of CFLAGS and pass them to configure instead.
|
2021-02-02 23:59:02 +00:00
|
|
|
if [ $SANITIZER == "coverage" ]; then
|
|
|
|
CFLAGS="`echo \"$CFLAGS\" | sed \"s/ $COVERAGE_FLAGS//\"`"
|
2021-02-15 17:40:12 +00:00
|
|
|
sanitizer_opts="$COVERAGE_FLAGS"
|
2021-02-02 23:59:02 +00:00
|
|
|
else
|
|
|
|
CFLAGS="`echo \"$CFLAGS\" | sed \"s/ $SANITIZER_FLAGS//\"`"
|
2021-02-15 17:40:12 +00:00
|
|
|
sanitizer_opts="$SANITIZER_FLAGS"
|
2021-01-27 16:16:16 +00:00
|
|
|
fi
|
2021-02-15 17:40:12 +00:00
|
|
|
# This is already added by --enable-fuzzer
|
|
|
|
CFLAGS="`echo \"$CFLAGS\" | sed \"s/ -fsanitize=fuzzer-no-link//\"`"
|
2021-01-27 16:16:16 +00:00
|
|
|
|
2021-02-15 17:40:12 +00:00
|
|
|
# Build sudo with static libs and enable fuzzing targets.
|
|
|
|
# All fuzz targets are integrated into the build process.
|
|
|
|
./configure --disable-shared --disable-shared-libutil --enable-static-sudoers \
|
|
|
|
--enable-sanitizer="$sanitizer_opts" --enable-fuzzer \
|
|
|
|
--enable-fuzzer-engine="$LIB_FUZZING_ENGINE" --enable-fuzzer-linker="$CXX" \
|
2021-02-02 23:59:02 +00:00
|
|
|
--disable-leaks --enable-warnings --enable-werror
|
|
|
|
make -j$(nproc)
|
|
|
|
|
2021-02-15 17:40:12 +00:00
|
|
|
# I/O log fuzzers
|
2021-02-02 23:59:02 +00:00
|
|
|
cd lib/iolog
|
|
|
|
|
2021-02-15 17:40:12 +00:00
|
|
|
# Fuzz legacy I/O log info parser
|
|
|
|
make fuzz_iolog_legacy && cp fuzz_iolog_legacy $OUT
|
|
|
|
rm -rf $WORK/corpus
|
2021-02-02 23:59:02 +00:00
|
|
|
mkdir $WORK/corpus
|
2021-02-15 17:40:12 +00:00
|
|
|
for f in `find regress/corpus/log_legacy -type f`; do
|
|
|
|
cp $f $WORK/corpus/`sha1sum $f | cut -d' ' -f1`
|
|
|
|
done
|
|
|
|
zip -j $OUT/fuzz_iolog_legacy_seed_corpus.zip $WORK/corpus/*
|
|
|
|
|
|
|
|
# Fuzz I/O log JSON parser
|
|
|
|
make fuzz_iolog_json && cp fuzz_iolog_json $OUT
|
|
|
|
rm -rf $WORK/corpus
|
|
|
|
mkdir $WORK/corpus
|
|
|
|
for f in `find regress/iolog_json -name '*.in'` `find regress/corpus/log_json -type f`; do
|
2021-02-02 23:59:02 +00:00
|
|
|
cp $f $WORK/corpus/`sha1sum $f | cut -d' ' -f1`
|
|
|
|
done
|
|
|
|
zip -j $OUT/fuzz_iolog_json_seed_corpus.zip $WORK/corpus/*
|
2021-02-15 17:40:12 +00:00
|
|
|
|
|
|
|
# Fuzz I/O log timing file parser
|
|
|
|
make fuzz_iolog_timing && cp fuzz_iolog_timing $OUT
|
2021-02-02 23:59:02 +00:00
|
|
|
rm -rf $WORK/corpus
|
2021-02-15 17:40:12 +00:00
|
|
|
mkdir $WORK/corpus
|
|
|
|
for f in `find regress/corpus/timing -type f`; do
|
|
|
|
cp $f $WORK/corpus/`sha1sum $f | cut -d' ' -f1`
|
|
|
|
done
|
|
|
|
zip -j $OUT/fuzz_iolog_timing_seed_corpus.zip $WORK/corpus/*
|
2021-01-27 16:16:16 +00:00
|
|
|
|
2021-02-15 17:40:12 +00:00
|
|
|
# Sudoers module fuzzers
|
2021-02-02 23:59:02 +00:00
|
|
|
cd ../../plugins/sudoers
|
|
|
|
|
2021-02-15 17:40:12 +00:00
|
|
|
# Fuzz sudoers parser
|
|
|
|
make fuzz_sudoers && cp fuzz_sudoers $OUT
|
|
|
|
rm -rf $WORK/corpus
|
2021-02-02 23:59:02 +00:00
|
|
|
mkdir $WORK/corpus
|
2021-02-15 17:40:12 +00:00
|
|
|
for f in ../../examples/sudoers `find regress/sudoers -name '*.in'`; do
|
2021-02-02 23:59:02 +00:00
|
|
|
cp $f $WORK/corpus/`sha1sum $f | cut -d' ' -f1`
|
|
|
|
done
|
|
|
|
zip -j $OUT/fuzz_sudoers_seed_corpus.zip $WORK/corpus/*
|
2021-01-27 16:16:16 +00:00
|
|
|
|
2021-02-02 23:59:02 +00:00
|
|
|
# Fuzz sudoers LDIF parser (used by cvtsudoers)
|
2021-02-15 17:40:12 +00:00
|
|
|
make fuzz_sudoers_ldif && cp fuzz_sudoers_ldif $OUT
|
|
|
|
rm -rf $WORK/corpus
|
2021-02-02 23:59:02 +00:00
|
|
|
mkdir $WORK/corpus
|
|
|
|
for f in `find regress/sudoers -name '*.ldif.ok' \! -size 0`; do
|
|
|
|
cp $f $WORK/corpus/`sha1sum $f | cut -d' ' -f1`
|
|
|
|
done
|
|
|
|
zip -j $OUT/fuzz_sudoers_ldif_seed_corpus.zip $WORK/corpus/*
|
2021-02-15 17:40:12 +00:00
|
|
|
|
|
|
|
# Fuzz sudoers policy module
|
|
|
|
make fuzz_policy && cp fuzz_policy $OUT
|
|
|
|
rm -rf $WORK/corpus
|
|
|
|
mkdir $WORK/corpus
|
|
|
|
for f in `find regress/corpus/policy -type f`; do
|
|
|
|
cp $f $WORK/corpus/`sha1sum $f | cut -d' ' -f1`
|
|
|
|
done
|
|
|
|
zip -j $OUT/fuzz_policy_seed_corpus.zip $WORK/corpus/*
|
|
|
|
|
|
|
|
# Cleanup
|
2021-02-02 23:59:02 +00:00
|
|
|
rm -rf $WORK/corpus
|