#!/bin/bash

export AFL_SKIP_CPUFREQ=1
export AFL_USE_ASAN=1
unset ASAN_OPTIONS

cd /tmp

git clone --depth 1 https://git.savannah.gnu.org/git/cpio.git
cd cpio
./bootstrap
./configure CC=afl-gcc CXX=afl-g++ LD=afl-gcc
make

mkdir x
echo hello > x/hello.txt
mkdir x/y
touch x/y/a.txt

mkdir in

find x/ -depth -print | cpio -oaV > in/test.cpio

mkdir /tmp/empty
chmod 500 /tmp/empty

afl-fuzz -i in -o out -m none src/cpio -i -D /tmp/empty
