<commit_before>#!/usr/bin/env bash

ORIGIN=`pwd`
AFL_BIN="$ORIGIN/downloads/afl-2.49b/afl-fuzz"
PHP_BIN="$ORIGIN/downloads/php-src/install/bin/php"

# Fuzzer configuration vars
MEM_LIMIT=500
SEEDS="$ORIGIN/aux/seeds/"
DRIVER="$ORIGIN/aux/driver.php"
DICTIONARY="$ORIGIN/aux/dictionary.txt"
OUTPUT_DIR="afl_working_dir"

SCREEN_SESS_NAME="fuzz"
SLAVE_COUNT=1

set -e
function ret_to_origin {
	cd "$ORIGIN"
}
trap ret_to_origin EXIT

if [[ ! "$#" -eq 2 ]]; then
	echo "[!] Usage: fuzz.sh outputdir slavecount"
	exit 1
fi

OUTPUT_DIR=$1
SLAVE_COUNT=$2

if [[ ! -f "$AFL_BIN" || ! -f "$PHP_BIN" ]]; then
	echo -n "[!] The AFL or PHP binaries are missing. Run get.sh and "
	echo "build.sh first."
	exit 1
fi
	
if ! hash screen 2>/dev/null; then
	echo "[!] GNU screen is not installed"
	exit 1
fi

echo "[+] Starting AFL (using $OUTPUT_DIR as the output directory) ..."
screen -dmAS "$SCREEN_SESS_NAME" -t master \
	"$AFL_BIN" -m "$MEM_LIMIT" -i "$SEEDS" -o \
	"$OUTPUT_DIR" -x "$DICTIONARY" -M -- "$PHP_BIN" "$DRIVER" @@

for i in $(seq 1 "$SLAVE_COUNT"); do
	echo "[+] Starting slave $i ..."
	NAME="slave$i"
	screen -S "$SCREEN_SESS_NAME" -X screen -t "$NAME" \
		"$AFL_BIN" -m "$MEM_LIMIT" -i "$SEEDS" \
		-o "$OUTPUT_DIR" -x "$DICTIONARY" -S "$NAME" -- \
		"$PHP_BIN" "$DRIVER" @@
done

echo "[+] Fuzzing started. Attach via 'screen -r $SCREEN_SESS_NAME'"
<commit_msg>Ensure there are enough cores for the slaves<commit_after>#!/usr/bin/env bash

ORIGIN=`pwd`
AFL_BIN="$ORIGIN/downloads/afl-2.49b/afl-fuzz"
PHP_BIN="$ORIGIN/downloads/php-src/install/bin/php"

# Fuzzer configuration vars
MEM_LIMIT=500
SEEDS="$ORIGIN/aux/seeds/"
DRIVER="$ORIGIN/aux/driver.php"
DICTIONARY="$ORIGIN/aux/dictionary.txt"
OUTPUT_DIR="afl_working_dir"

SCREEN_SESS_NAME="fuzz"
SLAVE_COUNT=1

CPU_COUNT=$(grep -c ^processor /proc/cpuinfo)

set -e
function ret_to_origin {
	cd "$ORIGIN"
}
trap ret_to_origin EXIT

if [[ ! "$#" -eq 2 ]]; then
	echo "[!] Usage: fuzz.sh outputdir slavecount"
	exit 1
fi

OUTPUT_DIR=$1
SLAVE_COUNT=$2

if [[ "$SLAVE_COUNT" -gt "$((CPU_COUNT - 1))" ]]; then
	echo "[!] You do not have enough cores to run that many slaves"
	exit 1
fi

if [[ ! -f "$AFL_BIN" || ! -f "$PHP_BIN" ]]; then
	echo -n "[!] The AFL or PHP binaries are missing. Run get.sh and "
	echo "build.sh first."
	exit 1
fi
	
if ! hash screen 2>/dev/null; then
	echo "[!] GNU screen is not installed"
	exit 1
fi

echo "[+] Starting AFL (using $OUTPUT_DIR as the output directory) ..."
screen -dmAS "$SCREEN_SESS_NAME" -t master \
	"$AFL_BIN" -m "$MEM_LIMIT" -i "$SEEDS" -o \
	"$OUTPUT_DIR" -x "$DICTIONARY" -M -- "$PHP_BIN" "$DRIVER" @@

for i in $(seq 1 "$SLAVE_COUNT"); do
	echo "[+] Starting slave $i ..."
	NAME="slave$i"
	screen -S "$SCREEN_SESS_NAME" -X screen -t "$NAME" \
		"$AFL_BIN" -m "$MEM_LIMIT" -i "$SEEDS" \
		-o "$OUTPUT_DIR" -x "$DICTIONARY" -S "$NAME" -- \
		"$PHP_BIN" "$DRIVER" @@
done

echo "[+] Fuzzing started. Attach via 'screen -r $SCREEN_SESS_NAME'"

{'fraction_non_alphanumeric': 0.18082936777702244, 'fraction_numerical': 0.010876954452753228, 'mean_word_length': 3.9712837837837838, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2569172', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1254, 'n_words': 318}