-# $OpenBSD: Makefile,v 1.18 2006/03/14 03:57:42 ray Exp $
+# $OpenBSD: Makefile,v 1.19 2008/08/20 09:29:51 mpf Exp $
# $NetBSD: Makefile,v 1.1 1997/12/30 23:27:11 cgd Exp $
-SUBDIR+= basename bc cap_mkdb dc diff diff3 dirname grep gzsig m4 make patch
-SUBDIR+= rcs sdiff sort ssh tsort
+SUBDIR+= basename bc cap_mkdb dc diff diff3 dirname grep gzip gzsig
+SUBDIR+= m4 make patch rcs sdiff sort ssh tsort
.include <bsd.subdir.mk>
--- /dev/null
+#!/bin/sh
+# $OpenBSD: t1.sh,v 1.1 2008/08/20 09:29:51 mpf Exp $
+
+# Test if gzip(1) detects truncated or corrupted files
+
+# Copyright (c) 2008 Marco Pfatschbacher <mpf@openbsd.org>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+# truncate at 2k
+gzip < /etc/rc | dd bs=1k count=2 of=t1.gz 2>/dev/null
+if gzip -vt t1.gz; then
+ echo "=> ERROR: truncation not detected!"
+ exit 1
+else
+ echo "=> OK"
+fi
+
+# truncate at 1k
+gzip < /etc/rc | dd bs=1k count=1 of=t1.gz 2>/dev/null
+if gzip -vt t1.gz; then
+ echo "=> ERROR: truncation not detected!"
+ exit 1
+else
+ echo "=> OK"
+fi
+
+# skip some data in the middle
+gzip < /etc/rc | dd bs=1k seek=1 >> t1.gz 2>/dev/null
+if gzip -vt t1.gz; then
+ echo "=> ERROR: corruption not detected!"
+ exit 1
+else
+ echo "=> OK"
+fi
+
+# simple fuzzer that modifies one random byte at a random offset
+
+gzip < /etc/rc > t1.gz
+for i in `jot 100`; do
+ where=$((RANDOM % 2048 + 256)) # random offset (but skip the header)
+ orig=`dd if=t1.gz skip=$where bs=1 count=1 2>/dev/null |\
+ hexdump -e '"%d"'`
+ fuzz=$((((orig + RANDOM) % 256) + 1))
+ if [ $fuzz = $orig ]; then
+ fuzz=$(((fuzz + 1) % 256))
+ fi
+ echo "$i/100: fuzzing byte @$where: $orig -> $fuzz"
+
+ if (dd if=t1.gz bs=1 count=$where 2>/dev/null; \
+ echo -n \\0`printf "%o" $fuzz`; \
+ dd if=t1.gz bs=1 skip=$((where+1)) 2>/dev/null) | gzip -tv; then
+ echo "=> ERROR: corruption not detected!"
+ exit 1
+ else
+ echo "=> OK"
+ fi
+done
+
+exit 0
--- /dev/null
+#!/bin/sh
+# $OpenBSD: t2.sh,v 1.1 2008/08/20 09:29:51 mpf Exp $
+
+# test basic gzip functionality
+
+gzip -c /etc/rc > t1.gz
+if ! gzip -vt t1.gz; then
+ echo "=> ERROR: could not gzip"
+ exit 1
+else
+ echo "=> OK"
+fi
+
+if ! gunzip -c t1.gz | cmp -s - /etc/rc; then
+ echo "=> ERROR: uncompressed file does not match"
+ gunzip -c t1.gz | diff - /etc/rc
+ exit 1
+else
+ echo "=> OK"
+fi
+
+gzip -c /etc/rc /etc/motd > t1.gz
+if ! gzip -vt t1.gz; then
+ echo "=> ERROR: could not gzip multiple files"
+ exit 1
+else
+ echo "=> OK"
+fi
+
+cat /etc/rc /etc/motd > rcmotd.test
+if ! gunzip -c t1.gz | cmp -s - rcmotd.test; then
+ echo "=> ERROR: gunzipped files do not match"
+ gunzip -c t1.gz | diff - rcmotd.test
+ exit 1
+else
+ echo "=> OK"
+fi
+
+exit 0