* Add a bunch of unit tests to check for zzuf basic capabilities: SIGSEGV
and SIGFPE detection, memory exhaustion detection.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -21,3 +21,6 @@ stamp-*
|
||||
src/zzuf
|
||||
test/zzcat
|
||||
test/zzero
|
||||
test/bug-div0
|
||||
test/bug-memory
|
||||
test/bug-overflow
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
EXTRA_DIST = rng utils file-00 file-ff file-random file-text
|
||||
|
||||
noinst_PROGRAMS = zzcat zzero
|
||||
noinst_PROGRAMS = zzcat zzero bug-overflow bug-memory bug-div0
|
||||
|
||||
TESTS = rng utils
|
||||
TESTS = check-rng check-overflow check-memory check-div0 check-utils
|
||||
|
||||
zzcat_SOURCES = zzcat.c
|
||||
|
||||
|
||||
31
test/bug-div0.c
Normal file
31
test/bug-div0.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* bug-div0 - program dividing by zero when fuzzed
|
||||
* Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int buf[1];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ch;
|
||||
|
||||
while((ch = getc(stdin)) != EOF)
|
||||
buf[0] = 1 / !ch;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
33
test/bug-memory.c
Normal file
33
test/bug-memory.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* bug-memory - program exhausting the memory when fuzzed
|
||||
* Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, ch;
|
||||
|
||||
while((ch = getc(stdin)) != EOF)
|
||||
{
|
||||
char *tmp = malloc(ch * 1024 * 1024);
|
||||
for(i = 0; i < 1024; i++)
|
||||
tmp[ch * 1024 * i] = i;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
31
test/bug-overflow.c
Normal file
31
test/bug-overflow.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* bug-overflow - program causing a buffer overflow when fuzzed
|
||||
* Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
char buf[1];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ch;
|
||||
|
||||
while((ch = getc(stdin)) != EOF)
|
||||
buf[ch * 1024 * 1024] = ch;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
58
test/check-div0
Executable file
58
test/check-div0
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
DIR="$(dirname "$0")"
|
||||
ZZUF="$DIR/../src/zzuf"
|
||||
PROGRAM="$DIR/bug-div0"
|
||||
if [ ! -f "$PROGRAM" ]; then
|
||||
echo "error: test/bug-div0 is missing"
|
||||
exit 1
|
||||
fi
|
||||
FAILED=0
|
||||
TESTED=0
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
seed=$(date | $ZZUF -m 2>/dev/null | cut -f2 -d' ' | tr -d abcdef | cut -b1-8)
|
||||
else
|
||||
seed="$1"
|
||||
fi
|
||||
|
||||
echo "*** running zzuf division-by-zero test with seed $seed ***"
|
||||
|
||||
echo "*** bug-div0 < /file-00"
|
||||
if ! $PROGRAM < "$DIR/file-00"; then
|
||||
echo "unexpected exit status $?"
|
||||
FAILED="$(($FAILED + 1))"
|
||||
else
|
||||
echo "*** test OK ***"
|
||||
fi
|
||||
TESTED="$(($TESTED + 1))"
|
||||
|
||||
echo "*** zzuf -qi -r0 bug-div0 < /file-00"
|
||||
if ! "$ZZUF" -r0 -qi "$PROGRAM" < "$DIR/file-00"; then
|
||||
echo "unexpected exit status $?"
|
||||
FAILED="$(($FAILED + 1))"
|
||||
else
|
||||
echo "*** test OK ***"
|
||||
fi
|
||||
TESTED="$(($TESTED + 1))"
|
||||
|
||||
echo "*** zzuf -qi bug-div0 < file-00"
|
||||
if "$ZZUF" -qi "$PROGRAM" < "$DIR/file-00"; then
|
||||
echo "unexpected exit status $?"
|
||||
FAILED="$(($FAILED + 1))"
|
||||
else
|
||||
echo "*** test OK ***"
|
||||
fi
|
||||
TESTED="$(($TESTED + 1))"
|
||||
|
||||
echo ""
|
||||
if [ "$FAILED" != 0 ]; then
|
||||
echo "*** $FAILED tests failed out of $TESTED ***"
|
||||
exit 1
|
||||
fi
|
||||
echo "*** all $TESTED tests OK ***"
|
||||
|
||||
exit 0
|
||||
|
||||
58
test/check-memory
Executable file
58
test/check-memory
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
DIR="$(dirname "$0")"
|
||||
ZZUF="$DIR/../src/zzuf"
|
||||
PROGRAM="$DIR/bug-memory"
|
||||
if [ ! -f "$PROGRAM" ]; then
|
||||
echo "error: test/bug-memory is missing"
|
||||
exit 1
|
||||
fi
|
||||
FAILED=0
|
||||
TESTED=0
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
seed=$(date | $ZZUF -m 2>/dev/null | cut -f2 -d' ' | tr -d abcdef | cut -b1-8)
|
||||
else
|
||||
seed="$1"
|
||||
fi
|
||||
|
||||
echo "*** running zzuf buffer memory test with seed $seed ***"
|
||||
|
||||
echo "*** bug-memory < /file-00"
|
||||
if ! $PROGRAM < "$DIR/file-00"; then
|
||||
echo "unexpected exit status $?"
|
||||
FAILED="$(($FAILED + 1))"
|
||||
else
|
||||
echo "*** test OK ***"
|
||||
fi
|
||||
TESTED="$(($TESTED + 1))"
|
||||
|
||||
echo "*** zzuf -qi -r0 bug-memory < /file-00"
|
||||
if ! "$ZZUF" -r0 -qi "$PROGRAM" < "$DIR/file-00"; then
|
||||
echo "unexpected exit status $?"
|
||||
FAILED="$(($FAILED + 1))"
|
||||
else
|
||||
echo "*** test OK ***"
|
||||
fi
|
||||
TESTED="$(($TESTED + 1))"
|
||||
|
||||
echo "*** zzuf -qi bug-memory < file-00"
|
||||
if "$ZZUF" -M 256 -qi "$PROGRAM" < "$DIR/file-00"; then
|
||||
echo "unexpected exit status $?"
|
||||
FAILED="$(($FAILED + 1))"
|
||||
else
|
||||
echo "*** test OK ***"
|
||||
fi
|
||||
TESTED="$(($TESTED + 1))"
|
||||
|
||||
echo ""
|
||||
if [ "$FAILED" != 0 ]; then
|
||||
echo "*** $FAILED tests failed out of $TESTED ***"
|
||||
exit 1
|
||||
fi
|
||||
echo "*** all $TESTED tests OK ***"
|
||||
|
||||
exit 0
|
||||
|
||||
58
test/check-overflow
Executable file
58
test/check-overflow
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
DIR="$(dirname "$0")"
|
||||
ZZUF="$DIR/../src/zzuf"
|
||||
PROGRAM="$DIR/bug-overflow"
|
||||
if [ ! -f "$PROGRAM" ]; then
|
||||
echo "error: test/bug-overflow is missing"
|
||||
exit 1
|
||||
fi
|
||||
FAILED=0
|
||||
TESTED=0
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
seed=$(date | $ZZUF -m 2>/dev/null | cut -f2 -d' ' | tr -d abcdef | cut -b1-8)
|
||||
else
|
||||
seed="$1"
|
||||
fi
|
||||
|
||||
echo "*** running zzuf buffer overflow test with seed $seed ***"
|
||||
|
||||
echo "*** bug-overflow < /file-00"
|
||||
if ! $PROGRAM < "$DIR/file-00"; then
|
||||
echo "unexpected exit status $?"
|
||||
FAILED="$(($FAILED + 1))"
|
||||
else
|
||||
echo "*** test OK ***"
|
||||
fi
|
||||
TESTED="$(($TESTED + 1))"
|
||||
|
||||
echo "*** zzuf -qi -r0 bug-overflow < /file-00"
|
||||
if ! "$ZZUF" -r0 -qi "$PROGRAM" < "$DIR/file-00"; then
|
||||
echo "unexpected exit status $?"
|
||||
FAILED="$(($FAILED + 1))"
|
||||
else
|
||||
echo "*** test OK ***"
|
||||
fi
|
||||
TESTED="$(($TESTED + 1))"
|
||||
|
||||
echo "*** zzuf -qi bug-overflow < file-00"
|
||||
if "$ZZUF" -qi "$PROGRAM" < "$DIR/file-00"; then
|
||||
echo "unexpected exit status $?"
|
||||
FAILED="$(($FAILED + 1))"
|
||||
else
|
||||
echo "*** test OK ***"
|
||||
fi
|
||||
TESTED="$(($TESTED + 1))"
|
||||
|
||||
echo ""
|
||||
if [ "$FAILED" != 0 ]; then
|
||||
echo "*** $FAILED tests failed out of $TESTED ***"
|
||||
exit 1
|
||||
fi
|
||||
echo "*** all $TESTED tests OK ***"
|
||||
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user