>From 57a95aff7d9ff9f257d934f823b7e4b1ae276caf Mon Sep 17 00:00:00 2001 From: Pavel Raiskup
Date: Thu, 13 Mar 2014 08:58:42 +0100 Subject: [PATCH] tar: fail if archive comes directly to/from terminal References: http://lists.gnu.org/archive/html/bug-tar/2014-03/msg00037.html * src/buffer.c (_open_archive): Check if isatty() and fail if yes. * tests/iotty.at: New testcase. * tests/Makefile.am: Handle new testcase. * tests/testsuite.at: Handle new testcase and define new macro AT_SCRIPT_PREREQ. --- src/buffer.c | 9 +++++++++ tests/Makefile.am | 1 + tests/iotty.at | 45 +++++++++++++++++++++++++++++++++++++++++++++ tests/testsuite.at | 7 +++++++ 4 files changed, 62 insertions(+) create mode 100644 tests/iotty.at diff --git a/src/buffer.c b/src/buffer.c index 95e8a26..9eb1434 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -732,6 +732,11 @@ _open_archive (enum access_mode wanted_access) archive = STDIN_FILENO; + if (isatty (archive)) + FATAL_ERROR ((0, 0, + _("Reading archive contents from terminal " + "input is not possible (missing -f option?)"))); + type = check_compressed_archive (&shortfile); if (type != ct_tar && type != ct_none) FATAL_ERROR ((0, 0, @@ -744,6 +749,10 @@ _open_archive (enum access_mode wanted_access) case ACCESS_WRITE: archive = STDOUT_FILENO; + if (isatty (archive)) + FATAL_ERROR ((0, 0, + _("Writing archive contents to terminal " + "output is not possible (missing -f option?)"))); if (!index_file_name) stdlis = stderr; break; diff --git a/tests/Makefile.am b/tests/Makefile.am index d4c9362..0ab28c8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -116,6 +116,7 @@ TESTSUITE_AT = \ incr09.at\ indexfile.at\ ignfail.at\ + iotty.at\ label01.at\ label02.at\ label03.at\ diff --git a/tests/iotty.at b/tests/iotty.at new file mode 100644 index 0000000..f89691c --- /dev/null +++ b/tests/iotty.at @@ -0,0 +1,45 @@ +# Process this file with autom4te to create testsuite. -*- Autotest -*- + +# Test suite for GNU tar. +# Copyright 2014 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