Files
tar/tests/testsuite.at
Paul Eggert df7b55a8f6 Fix some problems with negative and out-of-range integers.
Original problem reported for HP-UX LVM v2.2 by Michael White in
<http://lists.gnu.org/archive/html/bug-tar/2012-10/msg00000.html>.
This patch fixes some other gotchas that I noticed.
* gnulib.modules: Add extern-inline.
* src/common.h: Use _GL_INLINE_HEADER_BEGIN, _GL_INLINE_HEADER_END.
(COMMON_INLINE, max, min): New macros.
(represent_uintmax, valid_timespec): New inline functions.
(SYSINT_BUFSIZE): New constant.
(sysinttostr, strtosysint, decode_timespec): New decls.
* src/create.c (start_private_header): Silently bring the time_t
value into range; it is now the caller's responsibility to deal
with any overflow error.  Use uid 0 and gid 0 rather than the
user's uid/gid, since the faked header isn't "owned" by the user
and the uid/gid could in theory be out of range.  Leave major and
minor zeroed.
(FILL): Remove.
(write_gnu_long_link): Let start_private_header zero things out.
* src/create.c (write_gnu_long_link, write_extended):
* src/xheader.c (xheader_write_global):
Use start_time, not current time; no point hammering on the clock.
* src/compare.c (diff_multivol): Check that offset, size are in range.
* src/incremen.c (read_incr_db_01, write_directory_file_entry):
Allow negative time_t, dev_t, and ino_t.
* src/list.c (max): Remove (moved to common.h).
(read_header): Check that size is in range.
(from_header): Return intmax_t, not uintmax_t, to allow negative.
All callers changed.  At compile time, check assumptions about
intmax_t and uintmax_t.  Use bool for booleans.  Avoid overflow
hassles on picky hosts.
(mode_from_header): Last arg is now bool *, not unsigned *.
All callers changed.
(simple_print_header): Do not assume UID, GID fit in 'long'.
* src/list.c (from_header):
* src/xheader.c (out_of_range_header):
Arg is now a plain minimum value, not minus minval converted to
uintmax_t.  All callers changed.
* src/misc.c (COMMON_INLINE): New macro.
(sysinttostr, strtosysint, decode_timespec): New functions.
* src/sparse.c (oldgnu_add_sparse, oldgnu_fixup_header)
(star_fixup_header):
Check for offset overflow.
(decode_num): Clear errno before calling strtoumax.
* src/tar.c (expand_pax_option): Don't discard nanoseconds.
* src/xheader.c (assign_time_option): Allow negative time_t.
(decode_record): Simplify, since out-of-range string is guaranteed
to produce a value exceeding len_max.
(xheader_read): Last arg is off_t, not size_t.
Caller should diagnose negative arg, as needed.
Check that it's in range.
(enum decode_time_status): Remove.
(_decode_time): Remove, folding into decode_time.
(decode_time): Return bool, not enum decode_time_status.
Rely on decode_timespec to do most of the work.
(code_signed_num): New function.
(code_num): Use it.
(decode_signed_num): New function.
(decode_num): Use it.
(gid_coder, gid_decoder, uid_coder, uid_decoder, sparse_map_decoder)
(sparse_map_decoder): Code and decode negative values.
(sparse_map_decoder): Improve check for out-of-range values.
* tests/time01.at: New file.
* tests/Makefile.am (TESTSUITE_AT): Add it.
* tests/testsuite.at: Include it.
2012-12-22 20:41:52 -08:00

362 lines
8.5 KiB
Plaintext

# Process this file with autom4te to create testsuite. -*- Autotest -*-
# Test suite for GNU tar.
# Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2011, 2012 Free Software
# Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# We need a recent Autotest.
m4_version_prereq([2.52g])
m4_define([AT_TAR_CHECK_HOOK])
m4_define([AT_TAR_CHECK],[
AT_XFAIL_IF(test -f $[]XFAILFILE)
m4_foreach([FMT],
[m4_if([$7],[],[v7,oldgnu,ustar,posix,gnu],[$7])],
[AT_CHECK([
mkdir FMT
(cd FMT
TEST_TAR_FORMAT=FMT
export TEST_TAR_FORMAT
TAR_OPTIONS="-H FMT"
export TAR_OPTIONS
rm -rf *
$1)],$2,$3,$4,$5,$6)
AT_TAR_CHECK_HOOK])
])
m4_define([AT_TAR_WITH_HOOK],[
m4_pushdef([AT_TAR_CHECK_HOOK],[$1])
$2
m4_popdef([AT_TAR_CHECK_HOOK])])
m4_define([TAR_IGNREC_HOOK],[
AT_CHECK([grep -v '^.*tar: Record size = ' stderr; exit 0])
])
m4_define([RE_CHECK],[
AT_DATA([$1.re],[$2])
awk '{print NR " " $[]0}' $1 > $[]$.1
awk '{print NR " " $[]0}' $1.re | join - $[]$.1 |
while read NUM RE LINE
do
echo "$LINE" | grep -- "$RE" >/dev/null || exit 1
done
])
m4_define([AT_SKIP_TEST],[exit 77])
dnl AT_TARBALL_PREREQ(tarball, md5sum) - Check if test tarball exists
dnl in $TEST_DATA_DIR. If it does not, try to download it from
dnl $TEST_DATA_URL. If download fails, or it the file's md5 sum does not
dnl match second argument, skip the test.
m4_define([AT_TARBALL_PREREQ],[
test -z "$[]TEST_DATA_DIR" && AT_SKIP_TEST
tarball_prereq $1 $2 $[]TEST_DATA_DIR $[]TEST_DATA_URL || AT_SKIP_TEST])
dnl AT_STAR_PREREQ(tarball, md5sum) - Same for star testfiles
m4_define([AT_STAR_PREREQ],[
test -z "$STAR_TESTSCRIPTS" && AT_SKIP_TEST
tarball_prereq $1 $2 $[]STAR_TESTSCRIPTS $[]STAR_DATA_URL || AT_SKIP_TEST
])
dnl AT_GZIP_PREREQ - Skip test unless gzip (or $1) is available
m4_define([AT_GZIP_PREREQ],[
cat /dev/null | m4_if([$1],[],gzip,[$1]) - > /dev/null 2>&1 || AT_SKIP_TEST
])
dnl AT_SIGPIPE_PREREQ - Skip test unless SIGPIPE handling is the default
m4_define([AT_SIGPIPE_PREREQ],[
case `(cat "$at_myself" 2>&3 | :) 3>&1 >/dev/null` in #(
?*) AT_SKIP_TEST;;
esac
])
dnl AT_SORT_PREREQ - Skip test if sort utility outputs unwanted data on stderr
m4_define([AT_SORT_PREREQ],[
test -z "`sort < /dev/null 2>&1`" || AT_SKIP_TEST
])
dnl AT_UNPRIVILEGED_PREREQ - Skip test if running at root privileges
m4_define([AT_UNPRIVILEGED_PREREQ],[
echo "test" > $[]$
chmod 0 $[]$
cat $[]$ > /dev/null 2>&1
result=$?
rm -f $[]$
test $result -eq 0 && AT_SKIP_TEST
])
dnl AT_PRIVILEGED_PREREQ - Skip test if not running at root privileges
m4_define([AT_PRIVILEGED_PREREQ],[
echo "test" > $[]$
chmod 0 $[]$
cat $[]$ > /dev/null 2>&1
result=$?
rm -f $[]$
test $result -eq 0 || AT_SKIP_TEST
])
m4_define([AT_TAR_MKHIER],[
install-sh -d $1 >/dev/null dnl
m4_if([$2],,,&& genfile --file [$1]/[$2]) || AT_SKIP_TEST])
dnl Skip test when utlity does not return expected return value
m4_define([AT_CHECK_UTIL],[
$1 &> /dev/null
if test "$?" != $2; then
AT_SKIP_TEST
fi
])
m4_define([AT_XATTRS_UTILS_PREREQ],[
file=$( mktemp -p . )
AT_CHECK_UTIL(setfattr -n user.test -v test $file,0)
AT_CHECK_UTIL(getfattr $file,0)
])
m4_define([AT_SELINUX_UTILS_PREREQ],[
file=$( mktemp -p . )
AT_CHECK_UTIL(restorecon $file, 0)
AT_CHECK_UTIL(chcon -h --user=unconfined_u $file,0)
rm -rf $file
])
m4_define([AT_ACLS_UTILS_PREREQ],[
file=$( mktemp -p . )
AT_CHECK_UTIL(setfacl -m u:$UID:rwx $file,0)
AT_CHECK_UTIL(getfacl $file,0)
rm -rf $file
])
m4_define([AT_CAPABILITIES_UTILS_PREREQ],[
file=$( mktemp -p . )
AT_CHECK_UTIL(setcap "= cap_chown=ei" $file,0)
AT_CHECK_UTIL(getcap $file,0)
rm -rf $file
])
m4_define([AT_XATTRS_PREREQ],[
AT_XATTRS_UTILS_PREREQ
file=$( mktemp -p . )
setfattr -n user.test -v ahoj $file
# check whether tar fails to store xattrs
err=$( tar --xattrs -cf /dev/null $file 2>&1 >/dev/null | wc -l )
if test "$err" != "0"; then
AT_SKIP_TEST
fi
])
m4_define([AT_SELINUX_PREREQ],[
AT_SELINUX_UTILS_PREREQ
file=$( mktemp -p . )
err=$( tar --selinux -cf /dev/null $file 2>&1 >/dev/null | wc -l )
if test "$err" != "0"; then
AT_SKIP_TEST
fi
])
m4_define([AT_ACLS_PREREQ],[
AT_ACLS_UTILS_PREREQ
file=$( mktemp -p . )
setfacl -m u:$UID:rwx $file
err=$( tar --acls -cf /dev/null $file 2>&1 >/dev/null | wc -l )
if test "$err" != "0"; then
AT_SKIP_TEST
fi
])
m4_include([sparsemvp.at])
AT_INIT
AT_TESTED([tar])
m4_include([version.at])
m4_include([pipe.at])
m4_include([options.at])
m4_include([options02.at])
m4_include([T-empty.at])
m4_include([T-null.at])
m4_include([indexfile.at])
m4_include([verbose.at])
m4_include([append.at])
m4_include([append01.at])
m4_include([append02.at])
m4_include([append03.at])
m4_include([xform-h.at])
m4_include([xform01.at])
m4_include([exclude.at])
m4_include([exclude01.at])
m4_include([exclude02.at])
m4_include([exclude03.at])
m4_include([exclude04.at])
m4_include([exclude05.at])
m4_include([exclude06.at])
m4_include([exclude07.at])
m4_include([delete01.at])
m4_include([delete02.at])
m4_include([delete03.at])
m4_include([delete04.at])
m4_include([delete05.at])
m4_include([extrac01.at])
m4_include([extrac02.at])
m4_include([extrac03.at])
m4_include([extrac04.at])
m4_include([extrac05.at])
m4_include([extrac06.at])
m4_include([extrac07.at])
m4_include([extrac08.at])
m4_include([extrac09.at])
m4_include([extrac10.at])
m4_include([extrac11.at])
m4_include([extrac12.at])
m4_include([extrac13.at])
m4_include([extrac14.at])
m4_include([extrac15.at])
m4_include([extrac16.at])
m4_include([extrac17.at])
m4_include([extrac18.at])
m4_include([extrac19.at])
m4_include([label01.at])
m4_include([label02.at])
m4_include([label03.at])
m4_include([label04.at])
m4_include([label05.at])
m4_include([backup01.at])
m4_include([gzip.at])
m4_include([incremental.at])
m4_include([incr01.at])
m4_include([incr02.at])
m4_include([listed01.at])
m4_include([listed02.at])
m4_include([listed03.at])
m4_include([listed04.at])
m4_include([listed05.at])
m4_include([incr03.at])
m4_include([incr04.at])
m4_include([incr05.at])
m4_include([incr06.at])
m4_include([filerem01.at])
m4_include([filerem02.at])
m4_include([rename01.at])
m4_include([rename02.at])
m4_include([rename03.at])
m4_include([rename04.at])
m4_include([rename05.at])
m4_include([chtype.at])
m4_include([ignfail.at])
m4_include([link01.at])
m4_include([link02.at])
m4_include([link03.at])
m4_include([link04.at])
m4_include([longv7.at])
m4_include([long01.at])
m4_include([lustar01.at])
m4_include([lustar02.at])
m4_include([lustar03.at])
m4_include([time01.at])
m4_include([multiv01.at])
m4_include([multiv02.at])
m4_include([multiv03.at])
m4_include([multiv04.at])
m4_include([multiv05.at])
m4_include([multiv06.at])
m4_include([multiv07.at])
m4_include([multiv08.at])
m4_include([old.at])
m4_include([owner.at])
m4_include([recurse.at])
m4_include([same-order01.at])
m4_include([same-order02.at])
m4_include([shortrec.at])
m4_include([sparse01.at])
m4_include([sparse02.at])
m4_include([sparse03.at])
m4_include([sparse04.at])
m4_include([sparsemv.at])
m4_include([spmvp00.at])
m4_include([spmvp01.at])
m4_include([spmvp10.at])
m4_include([update.at])
m4_include([update01.at])
m4_include([update02.at])
m4_include([verify.at])
m4_include([volume.at])
m4_include([volsize.at])
m4_include([comprec.at])
m4_include([shortfile.at])
m4_include([shortupd.at])
m4_include([truncate.at])
m4_include([grow.at])
m4_include([remfiles01.at])
m4_include([remfiles02.at])
m4_include([remfiles03.at])
m4_include([sigpipe.at])
m4_include([xattr01.at])
m4_include([xattr02.at])
m4_include([xattr03.at])
m4_include([xattr04.at])
m4_include([xattr05.at])
m4_include([acls01.at])
m4_include([acls02.at])
m4_include([selnx01.at])
m4_include([selacl01.at])
m4_include([capabs_raw01.at])
m4_include([star/gtarfail.at])
m4_include([star/gtarfail2.at])
m4_include([star/multi-fail.at])
m4_include([star/ustar-big-2g.at])
m4_include([star/ustar-big-8g.at])
m4_include([star/pax-big-10g.at])