tar: don't crash if getcwd fails

* src/extract.c: Don't include xgetcwd.h.
(extract_dir): stat "." rather than statting getcwd's output.
* src/misc.c (normalize_filename_x): Rewrite so as not to resolve
/../, which can't be done reliably in the presence of symlinks.
Don't reject valid names such as ".".
(normalize_filename): Don't make it absolute; that way, we don't
have to invoke xgetcwd which might fail.  Don't bother to realloc
at the end, since that uses time and now saves little space.
(chdir_do): Don't crash if xgetcwd fails.
* tests/Makefile.am (TESTSUITE_AT): Add listed03.at.
* tests/listed03.at: New file.
* tests/testsuite.at: Include listed03.at.
This commit is contained in:
Paul R. Eggert
2010-07-15 11:25:15 -07:00
committed by Paul Eggert
parent ab6dd4948d
commit cc40c57a37
5 changed files with 92 additions and 91 deletions
+2 -1
View File
@@ -1,6 +1,6 @@
# Makefile for GNU tar regression tests.
# Copyright (C) 1996, 1997, 1999, 2000, 2001, 2003, 2004, 2005,
# Copyright (C) 1996, 1997, 1999, 2000, 2001, 2003, 2004, 2005,
# 2006, 2007, 2009 Free Software Foundation, Inc.
# François Pinard <pinard@iro.umontreal.ca>, 1988.
@@ -98,6 +98,7 @@ TESTSUITE_AT = \
link03.at\
listed01.at\
listed02.at\
listed03.at\
long01.at\
longv7.at\
lustar01.at\
+45
View File
@@ -0,0 +1,45 @@
# Process this file with autom4te to create testsuite. -*- Autotest -*-
# Test suite for GNU tar.
# Copyright (C) 2010 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, see <http://www.gnu.org/licenses/>.
# This checks for the --listed-incremental bug reported by J Chapman Flack at
# http://lists.gnu.org/archive/html/bug-tar/2010-06/msg00000.html
AT_SETUP([incremental dump when the parent directory is unreadable])
AT_KEYWORDS([listed incremental listed03])
AT_TAR_CHECK([
mkdir dir
mkdir dir/sub
mkdir dir/sub/a
genfile --file dir/sub/a/file
cd dir/sub
chmod a-r ..
tar -c -f archive.tar --listed-incremental=db.1 -v a
status=$?
chmod a+r ..
exit $status
],
[0],
[a/
a/file
],
[tar: a: Directory is new
],[],[],[gnu])
AT_CLEANUP
+3 -2
View File
@@ -41,13 +41,13 @@ $1)],$2,$3,$4,$5,$6)
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
@@ -162,6 +162,7 @@ m4_include([incr01.at])
m4_include([incr02.at])
m4_include([listed01.at])
m4_include([listed02.at])
m4_include([listed03.at])
m4_include([incr03.at])
m4_include([incr04.at])
m4_include([incr05.at])