Files
tar/tests/extrac35.at
T
Darren CarrerasandSergey Poznyakoff d1df7f403d tar: invalidate directory cache after failed open
fdbase_opendir copies a requested directory name into the cache before
opening it.  If open_subdir fails, this leaves the new name associated
with the old file descriptor.  A retry after tar creates the missing
parent can then extract into the old directory.

Close an unowned old descriptor before trying to open the new dir and
invalidate the cache entry if that fails.  Add a regression test using
equal-length sibling directory names.

* src/misc.c (fdbase_opendir): Invalidate the cache after a failed
replacement open.
* tests/extrac35.at: New test.
* tests/Makefile.am (TESTSUITE_AT): Add it.
* tests/testsuite.at: Include it.
2026-08-06 08:35:37 +03:00

38 lines
1.2 KiB
Plaintext

# Check failed parent lookup does not corrupt the directory cache. -*- Autotest -*-
# Copyright 2026 Free Software Foundation, Inc.
# This file is part of GNU tar.
# GNU tar 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 of the License, or
# (at your option) any later version.
# GNU tar 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/>.
AT_SETUP([failed parent lookup and directory cache])
AT_KEYWORDS([extract extrac35 chdir])
AT_TAR_CHECK([
mkdir -p src/a src/b dest
printf 'one\n' > src/a/one
printf 'two\n' > src/b/two
tar -cf archive.tar -C src --no-recursion a/one b/two &&
tar -xf archive.tar -C dest &&
test -f dest/a/one &&
test -f dest/b/two &&
test ! -e dest/a/two &&
cmp src/a/one dest/a/one &&
cmp src/b/two dest/b/two
])
AT_CLEANUP