>From e6e98c91b94f8bde4bd4b9a7ebc0a670695a1e42 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 from terminal References: http://lists.gnu.org/archive/html/bug-tar/2014-03/msg00037.html * src/buffer.c (_open_archive): Call avoid_terminal_io (). (avoid_terminal_io): New function; fails if isatty(archive). * 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 | 18 ++++++++++++++++++ tests/Makefile.am | 1 + tests/iotty.at | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tests/testsuite.at | 7 +++++++ 4 files changed, 72 insertions(+) create mode 100644 tests/iotty.at diff --git a/src/buffer.c b/src/buffer.c index 95e8a26..f2f56cb 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -668,6 +668,22 @@ init_buffer (void) record_end = record_start + blocking_factor; } +static void +avoid_terminal_io (enum access_mode wanted_access) +{ + if (0 != strcmp (archive_name_array[0], "-")) + return; + + /* do not fail if the tar's output goes directly to tty because such + behavior would go against GNU Coding Standards: + http://lists.gnu.org/archive/html/bug-tar/2014-03/msg00042.html */ + if (wanted_access == ACCESS_READ + && isatty (STDIN_FILENO)) + FATAL_ERROR ((0, 0, + _("I won't read archive contents from terminal " + "(missing -f option?)"))); +} + /* Open an archive file. The argument specifies whether we are reading or writing, or both. */ static void @@ -689,6 +705,8 @@ _open_archive (enum access_mode wanted_access) /* When updating the archive, we start with reading. */ access_mode = wanted_access == ACCESS_UPDATE ? ACCESS_READ : wanted_access; + avoid_terminal_io (access_mode); + read_full_records = read_full_records_option; records_read = 0; 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..5aae1d3 --- /dev/null +++ b/tests/iotty.at @@ -0,0 +1,46 @@ +# 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