bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: chmod bug fix: don't ignore a dangling symlink


From: Jim Meyering
Subject: FYI: chmod bug fix: don't ignore a dangling symlink
Date: Fri, 07 Sep 2007 10:50:26 +0200

Bob Proulx reported that chmod ignores dangling symlinks.
That's at odds with the documented behavior (affect referent
of each symlink), so I fixed it and added Bob's new test.

Here are the two latest change sets:

  * Add a test: demonstrate that chmod ignores a dangling symlink
  * chmod: don't ignore a dangling symlink


>From e70487cda746cc0800a02003c93f74621640e201 Mon Sep 17 00:00:00 2001
From: Bob Proulx <address@hidden>
Date: Fri, 7 Sep 2007 10:29:32 +0200
Subject: [PATCH] Add a test: demonstrate that chmod ignores a dangling symlink

* tests/chmod/thru-dangling: New test.  Fails.
* tests/chmod/Makefile.am (TESTS): Add thru-dangling.

Signed-off-by: Jim Meyering <address@hidden>
---
 ChangeLog                 |    6 ++++++
 tests/chmod/Makefile.am   |    1 +
 tests/chmod/thru-dangling |   45 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 0 deletions(-)
 create mode 100755 tests/chmod/thru-dangling

diff --git a/ChangeLog b/ChangeLog
index b880535..c09128b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-09-07  Bob Proulx  <address@hidden>
+
+       Add a test: demonstrate that chmod ignores a dangling symlink
+       * tests/chmod/thru-dangling: New test.  Fails.
+       * tests/chmod/Makefile.am (TESTS): Add thru-dangling.
+
 2007-09-05  Jim Meyering  <address@hidden>
 
        Adapt to new SELinux behavior: "?" vs. new "unlabeled"
diff --git a/tests/chmod/Makefile.am b/tests/chmod/Makefile.am
index 1388961..643015f 100644
--- a/tests/chmod/Makefile.am
+++ b/tests/chmod/Makefile.am
@@ -1,5 +1,6 @@
 ## Process this file with automake to produce Makefile.in -*-Makefile-*-.
 TESTS = \
+  thru-dangling \
   inaccessible \
   c-option \
   equal-x \
diff --git a/tests/chmod/thru-dangling b/tests/chmod/thru-dangling
new file mode 100755
index 0000000..d972a8a
--- /dev/null
+++ b/tests/chmod/thru-dangling
@@ -0,0 +1,45 @@
+#!/bin/sh
+# Test for proper error and exit code of chmod on a dangling symlink.
+
+# Copyright (C) 2007 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 of the License, 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/>.
+
+if test "$VERBOSE" = yes; then
+  set -x
+  chmod --version
+fi
+
+pwd=`pwd`
+t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
+trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit 
$status' 0
+trap '(exit $?); exit $?' 1 2 13 15
+
+framework_failure=0
+mkdir -p $tmp || framework_failure=1
+cd $tmp || framework_failure=1
+
+ln -s non-existent dangle || framework_failure=1
+
+if test $framework_failure = 1; then
+  echo "$0: failure in testing framework" 1>&2
+  (exit 1); exit 1
+fi
+
+fail=0
+
+# This operation cannot succeed since the symbolic link dangles.
+chmod 644 dangle && fail=1
+
+(exit $fail); exit $fail
-- 
1.5.3-dirty


>From 500eccdbe4d55b0cbf48cf264aa4232abd7c23df Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 7 Sep 2007 10:37:08 +0200
Subject: [PATCH] chmod: don't ignore a dangling symlink

* NEWS: Mention the bug fix.
* src/chmod.c (process_file): Handle the case of FTS_SLNONE,
i.e., give a diagnostic saying we cannot operate on such a file.
* tests/chmod/thru-dangling: Compare new stderr output with expected.

Signed-off-by: Jim Meyering <address@hidden>
---
 ChangeLog                 |    8 ++++++++
 NEWS                      |    4 ++++
 src/chmod.c               |    7 ++++++-
 tests/chmod/thru-dangling |    6 +++++-
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c09128b..a8c606b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-09-07  Jim Meyering  <address@hidden>
+
+       chmod: don't ignore a dangling symlink
+       * NEWS: Mention the bug fix.
+       * src/chmod.c (process_file): Handle the case of FTS_SLNONE,
+       i.e., give a diagnostic saying we cannot operate on such a file.
+       * tests/chmod/thru-dangling: Compare new stderr output with expected.
+
 2007-09-07  Bob Proulx  <address@hidden>
 
        Add a test: demonstrate that chmod ignores a dangling symlink
diff --git a/NEWS b/NEWS
index 6a0f18d..93a632c 100644
--- a/NEWS
+++ b/NEWS
@@ -70,6 +70,10 @@ GNU coreutils NEWS                                    -*- 
outline -*-
 
 ** Bug fixes
 
+  chmod no longer ignores a dangling symlink.  Now, chmod fails
+  with a diagnostic saying that it cannot operate on such a file.
+  [bug introduced in coreutils-5.1.0]
+
   cp attempts to read a regular file, even if stat says it is empty.
   Before, "cp /proc/cpuinfo c" would create an empty file when the kernel
   reports stat.st_size == 0, while "cat /proc/cpuinfo > c" would "work",
diff --git a/src/chmod.c b/src/chmod.c
index a670554..a22e5c1 100644
--- a/src/chmod.c
+++ b/src/chmod.c
@@ -1,5 +1,5 @@
 /* chmod -- change permission modes of files
-   Copyright (C) 89, 90, 91, 1995-2006 Free Software Foundation, Inc.
+   Copyright (C) 89, 90, 91, 1995-2007 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
@@ -220,6 +220,11 @@ process_file (FTS *fts, FTSENT *ent)
       ok = false;
       break;
 
+    case FTS_SLNONE:
+      error (0, 0, _("cannot operate on dangling symlink %s"),
+            quote (file_full_name));
+      ok = false;
+
     default:
       break;
     }
diff --git a/tests/chmod/thru-dangling b/tests/chmod/thru-dangling
index d972a8a..7a82db8 100755
--- a/tests/chmod/thru-dangling
+++ b/tests/chmod/thru-dangling
@@ -40,6 +40,10 @@ fi
 fail=0
 
 # This operation cannot succeed since the symbolic link dangles.
-chmod 644 dangle && fail=1
+chmod 644 dangle 2> out && fail=1
+
+echo "chmod: cannot operate on dangling symlink \`dangle'" > exp
+cmp out exp || fail=1
+test $fail = 1 && diff out exp 2> /dev/null
 
 (exit $fail); exit $fail
-- 
1.5.3-dirty




reply via email to

[Prev in Thread] Current Thread [Next in Thread]