test: add a regression test for a bug in our mmap function.

This commit is contained in:
Sam Hocevar 2015-01-16 01:12:46 +01:00
parent da669bb2b9
commit 4f7a76385a
4 changed files with 102 additions and 3 deletions

1
.gitignore vendored
View File

@ -39,6 +39,7 @@ test/zznop
test/zzone
test/bug-div0
test/bug-memory
test/bug-mmap
test/bug-overflow
# Test suite temporary files
test/*.log

View File

@ -1,14 +1,28 @@
EXTRA_DIST = $(TESTS) functions.inc file-00 file-ff file-random file-text
EXTRA_DIST = $(TESTS) \
functions.inc \
file-00 \
file-ff \
file-random \
file-text
noinst_PROGRAMS = zzero zznop zzone bug-overflow bug-memory bug-div0
noinst_PROGRAMS = zzero zznop zzone \
bug-overflow \
bug-memory \
bug-div0 \
bug-mmap
TESTS = check-zzuf-A-autoinc \
check-zzuf-f-fuzzing \
check-zzuf-m-md5 \
check-zzuf-M-max-memory \
check-zzuf-r-ratio \
check-source check-win32 check-overflow check-div0 check-utils
check-source \
check-win32 \
check-overflow \
check-div0 \
check-utils \
check-mmap
echo-sources: ; echo $(SOURCES)

43
test/bug-mmap.c Normal file
View File

@ -0,0 +1,43 @@
/*
* bug-mmap - regression test for a bug in zzuf
*
* Copyright © 20022015 Sam Hocevar <sam@hocevar.net>
* © 2015 Alexander Cherepanov <cherepan@mccme.ru>
*
* 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 the WTFPL Task Force.
* See http://www.wtfpl.net/ for more details.
*/
#include "config.h"
#define _BSD_SOURCE 1 /* for MAP_POPULATE */
#if HAVE_SYS_MMAN_H
# include <sys/mman.h>
#endif
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#if HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <fcntl.h>
#include <stdlib.h>
int main(void)
{
#if defined _SC_PAGE_SIZE
int fd = open("/etc/hosts", O_RDONLY);
mmap(0, sysconf(_SC_PAGE_SIZE) * 2, PROT_READ,
MAP_PRIVATE | MAP_POPULATE, fd, 0);
#endif
return EXIT_SUCCESS;
}

41
test/check-mmap Executable file
View File

@ -0,0 +1,41 @@
#!/bin/sh
#
# check-mmap - check that zzuf handles mmap() properly
#
# Copyright © 2002—2015 Sam Hocevar <sam@hocevar.net>
#
# 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 the WTFPL Task Force.
# See http://www.wtfpl.net/ for more details.
#
. "$(dirname "$0")/functions.inc"
ulimit -c 0
PROGRAM="$DIR/bug-mmap"
if [ ! -f "$PROGRAM" ]; then
echo "error: test/bug-mmap is missing"
exit 1
fi
start_test "zzuf buffer overflow test"
new_test "bug-mmap"
if ! $PROGRAM; then
fail_test " unexpected exit status $?"
else
pass_test " OK"
fi
new_test "zzuf -qi -r0 bug-mmap"
if ! $ZZUF -r0 -qi "$PROGRAM"; then
fail_test " unexpected exit status $?"
else
pass_test " OK"
fi
stop_test