More chown/chgrp dereferencing-related fixes.
authorJim Meyering <jim@meyering.net>
Fri, 13 Oct 2006 21:11:53 +0000 (21:11 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 13 Oct 2006 21:11:53 +0000 (21:11 +0000)
* src/chown-core.c (change_file_owner): Don't use fts_statp if
we're dereferencing symlinks.
Reverse conjuncts, so that we use dereference file_stats
(aka ent->fts_statp) only *after* we've confirmed that
chopt->affect_symlink_referent is true.  Otherwise, we might
use ent->fts_statp uninitialized.
Don't turn on FTS_NOSTAT when dereferencing symlinks.
* tests/chown/deref: Update the expected diagnostic, now that
this test case (trying to use "chown --dereference ..." on a
dangling symlink) takes a different code path.

ChangeLog
src/chown-core.c
tests/chown/deref

index aab0211..ddbe322 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2006-10-13  Jim Meyering  <jim@meyering.net>
+
+       More chown/chgrp dereferencing-related fixes.
+       * src/chown-core.c (change_file_owner): Don't use fts_statp if
+       we're dereferencing symlinks.
+       Reverse conjuncts, so that we use dereference file_stats
+       (aka ent->fts_statp) only *after* we've confirmed that
+       chopt->affect_symlink_referent is true.  Otherwise, we might
+       use ent->fts_statp uninitialized.
+       Don't turn on FTS_NOSTAT when dereferencing symlinks.
+       * tests/chown/deref: Update the expected diagnostic, now that
+       this test case (trying to use "chown --dereference ..." on a
+       dangling symlink) takes a different code path.
+
 2006-10-13  Paul Eggert  <eggert@cs.ucla.edu>
 
        Sync from Bison, as follows:
index d1efe52..8a0d51d 100644 (file)
@@ -305,7 +305,9 @@ change_file_owner (FTS *fts, FTSENT *ent,
       file_stats = NULL;
     }
   else if (required_uid == (uid_t) -1 && required_gid == (gid_t) -1
-          && chopt->verbosity == V_off && ! chopt->root_dev_ino)
+          && chopt->verbosity == V_off
+          && ! chopt->root_dev_ino
+          && ! chopt->affect_symlink_referent)
     {
       do_chown = true;
       file_stats = ent->fts_statp;
@@ -316,7 +318,7 @@ change_file_owner (FTS *fts, FTSENT *ent,
 
       /* If this is a symlink and we're dereferencing them,
         stat it to get info on the referent.  */
-      if (S_ISLNK (file_stats->st_mode) && chopt->affect_symlink_referent)
+      if (chopt->affect_symlink_referent && S_ISLNK (file_stats->st_mode))
        {
          if (fstatat (fts->fts_cwd_fd, file, &stat_buf, 0) != 0)
            {
@@ -454,6 +456,7 @@ chown_files (char **files, int bit_flags,
 
   /* Use lstat and stat only if they're needed.  */
   int stat_flags = ((required_uid != (uid_t) -1 || required_gid != (gid_t) -1
+                    || chopt->affect_symlink_referent
                     || chopt->verbosity != V_off || chopt->root_dev_ino)
                    ? 0
                    : FTS_NOSTAT);
index 2c7facd..dc91253 100755 (executable)
@@ -2,7 +2,7 @@
 # For coreutils-5.2.1 and earlier, chown --dereference would skip
 # symlinks having owner/group matching the specified owner/group.
 
-# Copyright (C) 2004 Free Software Foundation, Inc.
+# Copyright (C) 2004, 2006 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
@@ -50,7 +50,7 @@ chown --dereference $user dangle 2> out1 && fail=1
 sed 's/: [^:]*$//' out1 > out
 
 cat <<\EOF > exp || fail=1
-chown: changing ownership of `dangle'
+chown: cannot dereference `dangle'
 EOF
 
 cmp out exp || fail=1