Skip to content

Commit

Permalink
Add fuzzing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pbatard committed Mar 16, 2024
1 parent 1afd5f9 commit b51110c
Show file tree
Hide file tree
Showing 2 changed files with 267 additions and 6 deletions.
40 changes: 36 additions & 4 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
## @file
# Test script for MD5Sum.
#
# Copyright (c) 2023, Pete Batard <pete@akeo.ie>
# Copyright (c) 2023-2024, Pete Batard <pete@akeo.ie>
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
##

TEST_DIR=./run
LINE_LEN=60
LINE_LEN=64
TIMEOUT=2m
MIN_TEST="${1:-001}"
MAX_TEST="${2:-999}"
Expand All @@ -28,6 +28,16 @@ for t in $TEST_DIR/*.dat; do
base=$(basename "${t%.dat}")
test_number=${base:0:3}
test_name=${base:4}
use_diff=1
dump_hashlist=0

# If a test starts with 'Fuzzing', use grep instead of diff
# and also dump the generated md5sum.txt on error
if [[ "$test_name" =~ ^"Fuzzing" ]]; then
dump_hashlist=1
use_diff=0
fi

test_desc="Test #$test_number: ${test_name}... "
nb_lines=$(wc -l < "$t")
if [[ $nb_lines -eq 0 ]]; then
Expand Down Expand Up @@ -60,13 +70,29 @@ for t in $TEST_DIR/*.dat; do
err=$?
if [[ $err -eq 124 ]]; then
echo "[ERROR] (Time out)"
if [[ $dump_hashlist -ne 0 ]]; then
echo "Content of md5sum.txt was:"
echo "-------------------------------------------------------------------------------"
hexdump -C image/md5sum.txt
echo "-------------------------------------------------------------------------------"
fi
NUM_ERROR=$((NUM_ERROR + 1))
elif [[ $err -ne 0 ]]; then
echo "[ERROR]"
echo "[ERROR] ($err)"
cat error.txt
if [[ $dump_hashlist -ne 0 ]]; then
echo "Content of md5sum.txt was:"
echo "-------------------------------------------------------------------------------"
hexdump -C image/md5sum.txt
echo "-------------------------------------------------------------------------------"
fi
NUM_ERROR=$((NUM_ERROR + 1))
else
tail -n $nb_lines output.txt | diff -Z --strip-trailing-cr -q "$t" - >/dev/null 2>&1
if [[ $use_diff -ne 0 ]]; then
tail -n $nb_lines output.txt | diff -Z --strip-trailing-cr -q "$t" - >/dev/null 2>&1
else
tail -n +3 output.txt | grep -F -f "$t" >/dev/null 2>&1
fi
if [[ $? -eq 0 ]]; then
echo "[PASS]"
NUM_PASS=$((NUM_PASS + 1))
Expand All @@ -77,6 +103,12 @@ for t in $TEST_DIR/*.dat; do
echo "-------------------------------------------------------------------------------"
tail -n +3 output.txt
echo "-------------------------------------------------------------------------------"
if [[ $dump_hashlist -ne 0 ]]; then
echo "Content of md5sum.txt was:"
echo "-------------------------------------------------------------------------------"
hexdump -C image/md5sum.txt
echo "-------------------------------------------------------------------------------"
fi
fi
fi

Expand Down
233 changes: 231 additions & 2 deletions tests/test_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ Test bootloader
Test bootloader
< rm -f image/efi/boot/*_original.efi

# Progress with TotalBytes too small
# Progress with TotalBytes too small
> echo "# md5sum_totalbytes = 0x1" > image/md5sum.txt
> for i in {64..1024..64}; do dd if=/dev/urandom of=image/file$i bs=1k count=$i; done
> (cd image; md5sum file* >> md5sum.txt)
Expand Down Expand Up @@ -332,7 +332,7 @@ file960 (960 KB)
16/16 files processed [0 failed]
< rm image/file*

# Progress with TotalBytes too large
# Progress with TotalBytes too large
> echo "# md5sum_totalbytes = 0x1234567890abcdef" > image/md5sum.txt
> for i in {64..1024..64}; do dd if=/dev/urandom of=image/file$i bs=1k count=$i; done
> (cd image; md5sum file* >> md5sum.txt)
Expand All @@ -355,3 +355,232 @@ file896 (896 KB)
file960 (960 KB)
16/16 files processed [0 failed]
< rm image/file*

# Fuzzing test: 100 Random bytes in hash list
> dd if=/dev/urandom bs=100 count=1 of=image/md5sum.txt
[21] Aborted

# Fuzzing test: 1000 Random bytes in hash list
> dd if=/dev/urandom bs=1000 count=1 of=image/md5sum.txt
[21] Aborted

# Fuzzing test: 10000 Random bytes in hash list
> dd if=/dev/urandom bs=10000 count=1 of=image/md5sum.txt
[21] Aborted

# Fuzzing test: 100000 Random bytes in hash list
> dd if=/dev/urandom bs=100000 count=1 of=image/md5sum.txt
[21] Aborted

# Fuzzing test: 50 Random bytes in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> dd if=/dev/urandom bs=50 count=1 >> image/md5sum.txt
[21] Aborted

# Fuzzing test: 100 Random bytes in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> dd if=/dev/urandom bs=100 count=1 >> image/md5sum.txt
[21] Aborted

# Fuzzing test: 150 Random bytes in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> dd if=/dev/urandom bs=150 count=1 >> image/md5sum.txt
[21] Aborted

# Fuzzing test: 200 Random bytes in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> dd if=/dev/urandom bs=200 count=1 >> image/md5sum.txt
[21] Aborted

# Fuzzing test: 250 Random bytes in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> dd if=/dev/urandom bs=250 count=1 >> image/md5sum.txt
[21] Aborted

# Fuzzing test: 300 Random bytes in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> dd if=/dev/urandom bs=300 count=1 >> image/md5sum.txt
[21] Aborted

# Fuzzing test: 350 Random bytes in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> dd if=/dev/urandom bs=350 count=1 >> image/md5sum.txt
[21] Aborted

# Fuzzing test: 400 Random bytes in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> dd if=/dev/urandom bs=400 count=1 >> image/md5sum.txt
[21] Aborted

# Fuzzing test: 450 Random bytes in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> dd if=/dev/urandom bs=450 count=1 >> image/md5sum.txt
[21] Aborted

# Fuzzing test: 500 Random bytes in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> dd if=/dev/urandom bs=500 count=1 >> image/md5sum.txt
[21] Aborted

# Fuzzing test: 550 Random bytes in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> dd if=/dev/urandom bs=550 count=1 >> image/md5sum.txt
[21] Aborted

# Fuzzing test: 50 Random chars in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -d '[:cntrl:]' </dev/urandom | head -c 50 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 100 Random chars in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -d '[:cntrl:]' </dev/urandom | head -c 100 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 150 Random chars in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -d '[:cntrl:]' </dev/urandom | head -c 150 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 200 Random chars in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -d '[:cntrl:]' </dev/urandom | head -c 200 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 250 Random chars in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -d '[:cntrl:]' </dev/urandom | head -c 250 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 300 Random chars in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -d '[:cntrl:]' </dev/urandom | head -c 300 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 350 Random chars in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -d '[:cntrl:]' </dev/urandom | head -c 350 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 400 Random chars in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -d '[:cntrl:]' </dev/urandom | head -c 400 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 450 Random chars in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -d '[:cntrl:]' </dev/urandom | head -c 450 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 500 Random chars in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -d '[:cntrl:]' </dev/urandom | head -c 500 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 550 Random chars in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -d '[:cntrl:]' </dev/urandom | head -c 550 >> image/md5sum.txt
[21] Aborted

# Fuzzing test: 50 Random ascii in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -cd '[:print:]' </dev/urandom | head -c 50 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 100 Random ascii in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -cd '[:print:]' </dev/urandom | head -c 100 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 150 Random ascii in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -cd '[:print:]' </dev/urandom | head -c 150 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 200 Random ascii in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -cd '[:print:]' </dev/urandom | head -c 200 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 250 Random ascii in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -cd '[:print:]' </dev/urandom | head -c 250 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 300 Random ascii in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -cd '[:print:]' </dev/urandom | head -c 300 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 350 Random ascii in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -cd '[:print:]' </dev/urandom | head -c 350 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 400 Random ascii in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -cd '[:print:]' </dev/urandom | head -c 400 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 450 Random ascii in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -cd '[:print:]' </dev/urandom | head -c 450 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 500 Random ascii in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -cd '[:print:]' </dev/urandom | head -c 500 >> image/md5sum.txt
1/1 file processed [1 failed]

# Fuzzing test: 550 Random ascii in path
> tr -cd '0-9a-f' </dev/urandom | head -c 32 > image/md5sum.txt
> echo -n " " >> image/md5sum.txt
> tr -cd '[:print:]' </dev/urandom | head -c 550 >> image/md5sum.txt
[21] Aborted

# Fuzzing test: Random bytes in hash
> dd if=/dev/urandom bs=32 count=1 > image/md5sum.txt
> echo " some/path" >> image/md5sum.txt
[21] Aborted

# Fuzzing test: Random ascii in hash
> tr -cd '[:print:]' </dev/urandom | head -c 32 > image/md5sum.txt
> echo " some/path" >> image/md5sum.txt
[21] Aborted

# Fuzzing test: Random hexascii in hash
> tr -cd '0-9a-fA-F' </dev/urandom | head -c 32 > image/md5sum.txt
> echo " some/path" >> image/md5sum.txt
[14] Not Found

0 comments on commit b51110c

Please sign in to comment.