Differential fuzzing for libhtp-rs (#9359)

We are transitioning from libhtp C to libhtp in rust

So, here is the update of the project to fuzz the coming rust version,
and also do differential fuzzing between them to check that they have
the same behavior...
This commit is contained in:
Catena cyber 2023-01-09 17:02:41 +01:00 committed by GitHub
parent 81902af8c7
commit 9ba905cdfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 6 deletions

View File

@ -14,8 +14,10 @@
# #
################################################################################ ################################################################################
FROM gcr.io/oss-fuzz-base/base-builder FROM gcr.io/oss-fuzz-base/base-builder-rust
RUN apt-get update && apt-get install -y make autoconf automake libtool zlib1g-dev liblzma-dev RUN apt-get update && apt-get install -y make autoconf automake libtool zlib1g-dev liblzma-dev
RUN git clone --depth 1 https://github.com/OISF/libhtp.git libhtp RUN git clone --depth 1 https://github.com/OISF/libhtp.git libhtp
RUN git clone --depth 1 https://github.com/cccs-rtmorti/libhtp-rs.git libhtp-rs
WORKDIR $SRC WORKDIR $SRC
COPY build.sh $SRC/ COPY build.sh $SRC/
COPY multiple.txt $SRC/

View File

@ -16,14 +16,37 @@
################################################################################ ################################################################################
# build project # build project
(
cd libhtp-rs
export CARGO_BUILD_TARGET="x86_64-unknown-linux-gnu"
cargo fuzz build -O
cargo fuzz list | while read i; do
# debug for coverage build
cp fuzz/target/x86_64-unknown-linux-gnu/release/$i $OUT/ || cp fuzz/target/x86_64-unknown-linux-gnu/debug/$i $OUT/
done
if [ "$SANITIZER" = "address" ]
then
export RUSTFLAGS="$RUSTFLAGS -Cpasses=sancov-module -Cllvm-args=-sanitizer-coverage-level=4 -Cllvm-args=-sanitizer-coverage-trace-compares -Cllvm-args=-sanitizer-coverage-inline-8bit-counters -Cllvm-args=-sanitizer-coverage-trace-geps -Cllvm-args=-sanitizer-coverage-prune-blocks=0 -Cllvm-args=-sanitizer-coverage-pc-table -Clink-dead-code -Cllvm-args=-sanitizer-coverage-stack-depth"
fi
cat $SRC/multiple.txt | while read i; do
git grep $i | cut -d: -f1 | uniq | xargs sed -i -e s/$i/"$i"_rs/;
done
cargo build
cp ./target/x86_64-unknown-linux-gnu/debug/libhtp.a ../libhtp-rs.a
)
cd libhtp cd libhtp
sh autogen.sh sh autogen.sh
./configure ./configure
make make -j$(nproc)
$CC $CFLAGS -I. -c test/fuzz/fuzz_htp.c -o fuzz_htp.o $CC $CFLAGS -I. -c test/fuzz/fuzz_htp.c -o fuzz_htp.o
$CC $CFLAGS -I. -c test/test.c -o test.o $CC $CFLAGS -I. -c test/test.c -o test.o
$CXX $CXXFLAGS fuzz_htp.o test.o -o $OUT/fuzz_htp ./htp/.libs/libhtp.a $LIB_FUZZING_ENGINE -lz -llzma $CXX $CXXFLAGS fuzz_htp.o test.o -o $OUT/fuzz_htp_c ./htp/.libs/libhtp.a $LIB_FUZZING_ENGINE -lz -llzma
$CC $CFLAGS -I. -c test/fuzz/fuzz_diff.c -o fuzz_diff.o
$CXX $CXXFLAGS fuzz_diff.o test.o -o $OUT/fuzz_diff ./htp/.libs/libhtp.a ../libhtp-rs.a $LIB_FUZZING_ENGINE -lz -llzma
# builds corpus # builds corpus
zip -r $OUT/fuzz_htp_seed_corpus.zip test/files/*.t zip -r $OUT/fuzz_htp_seed_corpus.zip test/files/*.t
zip -r $OUT/fuzz_diff_seed_corpus.zip test/files/*.t

11
projects/libhtp/multiple.txt Executable file
View File

@ -0,0 +1,11 @@
bstr_alloc
bstr_free
bstr_cmp_c
bstr_dup_c
bstr_util_strdup_to_c
bstr_len
bstr_ptr
htp_connp_
htp_tx_destroy
htp_tx_set_user_data
htp_tx_register_response_body_data

View File

@ -1,5 +1,5 @@
homepage: "https://github.com/OISF/libhtp" homepage: "https://github.com/OISF/libhtp"
language: c++ language: rust
primary_contact: "vjulien@openinfosecfoundation.org" primary_contact: "vjulien@openinfosecfoundation.org"
auto_ccs : auto_ccs :
- "p.antoine@catenacyber.fr" - "p.antoine@catenacyber.fr"
@ -9,5 +9,6 @@ sanitizers:
- address - address
# Disabled MSAN because of https://github.com/google/oss-fuzz/issues/6294 # Disabled MSAN because of https://github.com/google/oss-fuzz/issues/6294
# - memory # - memory
- undefined fuzzing_engines:
- libfuzzer
main_repo: 'https://github.com/OISF/libhtp.git' main_repo: 'https://github.com/OISF/libhtp.git'