GNU bug report logs - #15376
install-sh -t accepts arguments that are not a directory

Previous Next

Package: automake;

Reported by: Tobias Hansen <thansen <at> debian.org>

Date: Fri, 13 Sep 2013 23:41:01 UTC

Severity: minor

Tags: patch

Found in version 1.14

Done: Stefano Lattarini <stefano.lattarini <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 15376 in the body.
You can then email your comments to 15376 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-automake <at> gnu.org:
bug#15376; Package automake. (Fri, 13 Sep 2013 23:41:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tobias Hansen <thansen <at> debian.org>:
New bug report received and forwarded. Copy sent to bug-automake <at> gnu.org. (Fri, 13 Sep 2013 23:41:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tobias Hansen <thansen <at> debian.org>
To: bug-automake <at> gnu.org
Subject: install-sh -t accepts arguments that are not a directory
Date: Sat, 14 Sep 2013 01:06:25 +0200
[Message part 1 (text/plain, inline)]
Version: 1.14
Tags: patch

Hi automake maintainers,

the -t parameter of install-sh is supposed to accept a target directory.
If it is given a file or a name of a non-existent file/directory, the
source is copied into this file. For example, if I have a file foo and do

install-sh -t foo2 foo

I will have the two files foo and foo2. install-sh should abort whenever
the argument of the -t option is not a directory, just like install
does. Attached is a patch that fixes the issue.

Best regards,
Tobias Hansen
[install-sh_t_check_directory.patch (text/x-diff, attachment)]

Information forwarded to bug-automake <at> gnu.org:
bug#15376; Package automake. (Wed, 25 Dec 2013 23:19:02 GMT) Full text and rfc822 format available.

Message #8 received at 15376 <at> debbugs.gnu.org (full text, mbox):

From: Stefano Lattarini <stefano.lattarini <at> gmail.com>
To: Tobias Hansen <thansen <at> debian.org>
Cc: 15376 <at> debbugs.gnu.org,
 "automake-patches <at> gnu.org" <automake-patches <at> gnu.org>
Subject: [PATCH] install-sh: be stricter in catching invalid usages
Date: Thu, 26 Dec 2013 00:18:14 +0100
[Message part 1 (text/plain, inline)]
severity 15376 minor
tags 15376 + patch
close 15376
stop

Reference:
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15376

Hi Tobias, thanks for the report and the patch, and sorry for the
shameful delay.  I've adjusted the problem you reported, plus other
similar issues I noticed along the way, with the attached patch.

Thank you,
  Stefano

[0001-install-sh-be-stricter-in-catching-invalid-usages.patch (text/x-patch, attachment)]

Severity set to 'minor' from 'normal' Request was from Stefano Lattarini <stefano.lattarini <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 25 Dec 2013 23:19:03 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 15376 <at> debbugs.gnu.org and Tobias Hansen <thansen <at> debian.org> Request was from Stefano Lattarini <stefano.lattarini <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 25 Dec 2013 23:19:04 GMT) Full text and rfc822 format available.

Information forwarded to bug-automake <at> gnu.org:
bug#15376; Package automake. (Wed, 25 Dec 2013 23:43:02 GMT) Full text and rfc822 format available.

Message #15 received at 15376 <at> debbugs.gnu.org (full text, mbox):

From: Stefano Lattarini <stefano.lattarini <at> gmail.com>
To: automake-patches <at> gnu.org
Cc: 15376 <at> debbugs.gnu.org, Tobias Hansen <thansen <at> debian.org>
Subject: [FYI] {minor} install-sh: a slightly better diagnostic,
 and tests enhancements
Date: Thu, 26 Dec 2013 00:42:44 +0100
* lib/install-sh: When called with no non-option arguments and the '-t'
option with an argument that is not an existing directory, have the
diagnostic output complain about the lack of required arguments rather
than about the bad argument passed to '-t'.
* t/install-sh-unittests.sh: Enhance to also check diagnostic printed
in cases of expected failure.

Signed-off-by: Stefano Lattarini <stefano.lattarini <at> gmail.com>
---
 lib/install-sh            | 18 +++++++++---------
 t/install-sh-unittests.sh | 38 ++++++++++++++++++++++++++------------
 2 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/lib/install-sh b/lib/install-sh
index d8de87f..0b0fdcb 100755
--- a/lib/install-sh
+++ b/lib/install-sh
@@ -193,15 +193,6 @@ if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
   done
 fi
 
-if test -z "$dir_arg"; then
-  if test $# -gt 1 || test "$is_target_a_directory" = always; then
-    if test ! -d "$dst_arg"; then
-      echo "$0: $dst_arg: Is not a directory." >&2
-      exit 1
-    fi
-  fi
-fi
-
 if test $# -eq 0; then
   if test -z "$dir_arg"; then
     echo "$0: no input file specified." >&2
@@ -213,6 +204,15 @@ if test $# -eq 0; then
 fi
 
 if test -z "$dir_arg"; then
+  if test $# -gt 1 || test "$is_target_a_directory" = always; then
+    if test ! -d "$dst_arg"; then
+      echo "$0: $dst_arg: Is not a directory." >&2
+      exit 1
+    fi
+  fi
+fi
+
+if test -z "$dir_arg"; then
   do_exit='(exit $ret); exit $ret'
   trap "ret=129; $do_exit" 1
   trap "ret=130; $do_exit" 2
diff --git a/t/install-sh-unittests.sh b/t/install-sh-unittests.sh
index 1b85c9c..dff0c51 100644
--- a/t/install-sh-unittests.sh
+++ b/t/install-sh-unittests.sh
@@ -19,23 +19,37 @@
 am_create_testdir=empty
 . test-init.sh
 
+install_sh_fail () 
+{
+  err_rx=$1; shift
+  ./install-sh ${1+"$@"} 2>stderr && { cat stderr >&2; exit 1; }
+  cat stderr >&2
+  $EGREP "install-sh:.* $err_rx" stderr || exit 1
+}
+
 get_shell_script install-sh
 
 # Basic errors.
-./install-sh && exit 1
-./install-sh -m 644 dest && exit 1
+install_sh_fail 'no input file specified'
+install_sh_fail 'no input file specified' dest
+install_sh_fail 'no input file specified' -m 644 dest
+install_sh_fail 'no input file specified' -c -t dest
 
 # Incorrect usages.
 : > bar
 : > baz
 : > qux
-./install-sh -d -t foo && exit 1
-./install-sh -d -t foo bar && exit 1
-./install-sh -t foo bar && exit 1
-./install-sh bar baz foo && exit 1
+install_sh_fail 'target directory not allowed when installing a directory' \
+                -d -t foo
+install_sh_fail 'target directory not allowed when installing a directory' \
+                -d -t foo bar
+install_sh_fail 'foo: [iI]s not a directory' -t foo bar
+install_sh_fail 'foo: [iI]s not a directory' bar baz foo
 mkdir foo
-./install-sh -d -t foo && exit 1
-./install-sh -d -t foo bar && exit 1
+install_sh_fail 'target directory not allowed when installing a directory' \
+                -d -t foo
+install_sh_fail 'target directory not allowed when installing a directory' \
+                -d -t foo bar
 rmdir foo
 rm -f bar baz qux
 
@@ -96,8 +110,8 @@ test -f d4/z
 ./install-sh -T x d3/y
 test -f x
 test -f d3/y
-./install-sh -T x d3 && exit 1
-./install-sh -T x d4// && exit 1
+install_sh_fail 'd3: [iI]s a directory' -T x d3
+install_sh_fail 'd4(//)?: [iI]s a directory' -T x d4//
 
 # Ensure that install-sh works with names that include spaces.
 touch 'a  b'
@@ -108,8 +122,8 @@ test -f 'a  b'
 
 # Ensure we do not run into 'test' operator precedence bugs with Tru64 sh.
 for c in = '(' ')' '!'; do
-  ./install-sh $c 2>stderr && { cat stderr >&2; exit 1; }
-  cat stderr >&2
+  install_sh_fail 'no input file specified' $c
+  test -f stderr # sanity check
   grep 'test: ' stderr && exit 1
   # Skip tests if the file system is not capable.
   mkdir ./$c || continue
-- 
1.8.5.rc0.335.g7794a68





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 23 Jan 2014 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 243 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.