diff --git a/.gitignore b/.gitignore index e4eadaa..98c0e9a 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/test/Makefile.am b/test/Makefile.am index 80e6b23..7a3719c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -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) diff --git a/test/bug-mmap.c b/test/bug-mmap.c new file mode 100644 index 0000000..af371dc --- /dev/null +++ b/test/bug-mmap.c @@ -0,0 +1,43 @@ +/* + * bug-mmap - regression test for a bug in zzuf + * + * Copyright © 2002—2015 Sam Hocevar + * © 2015 Alexander Cherepanov + * + * 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 +#endif +#if HAVE_SYS_TYPES_H +# include +#endif +#if HAVE_SYS_STAT_H +# include +#endif +#if HAVE_UNISTD_H +# include +#endif +#include +#include + +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; +} + diff --git a/test/check-mmap b/test/check-mmap new file mode 100755 index 0000000..68fcee6 --- /dev/null +++ b/test/check-mmap @@ -0,0 +1,41 @@ +#!/bin/sh +# +# check-mmap - check that zzuf handles mmap() properly +# +# Copyright © 2002—2015 Sam Hocevar +# +# 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 +