diff options
author | Jim Meyering <jim@meyering.net> | 2007-01-10 22:00:44 +0100 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2007-01-10 22:00:44 +0100 |
commit | b5f1873022d7abc93313df2dfd16d8aa58119916 (patch) | |
tree | 63ea596a2d40860cbf6211285e9a6891e2359010 | |
parent | dad7d86d57d2a6351ba1a395109760dce8977a91 (diff) | |
download | coreutils-b5f1873022d7abc93313df2dfd16d8aa58119916.tar.xz |
Don't use fts_statp uninitialized for "chown -RLh --preserve-root ...".
* src/chown-core.c (FTSENT_IS_DIRECTORY): New macro.
(change_file_owner): Perform the ROOT_DEV_INO_CHECK only for a
directory. Non-directory entries lack fts_statp data when using
the FTS_NOSTAT option.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | src/chown-core.c | 12 |
2 files changed, 18 insertions, 2 deletions
@@ -1,3 +1,11 @@ +2007-01-10 Jim Meyering <jim@meyering.net> + + Don't use fts_statp uninitialized for "chown -RLh --preserve-root ...". + * src/chown-core.c (FTSENT_IS_DIRECTORY): New macro. + (change_file_owner): Perform the ROOT_DEV_INO_CHECK only for a + directory. Non-directory entries lack fts_statp data when using + the FTS_NOSTAT option. + 2007-01-07 Jim Meyering <jim@meyering.net> * tests/sample-test: Update copyright date to 2007. diff --git a/src/chown-core.c b/src/chown-core.c index b39061091..bd987a8c1 100644 --- a/src/chown-core.c +++ b/src/chown-core.c @@ -1,5 +1,5 @@ /* chown-core.c -- core functions for changing ownership. - Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006 Free Software Foundation. + Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation. 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 @@ -32,6 +32,12 @@ #include "root-dev-ino.h" #include "xfts.h" +#define FTSENT_IS_DIRECTORY(E) \ + ((E)->fts_info == FTS_D \ + || (E)->fts_info == FTS_DC \ + || (E)->fts_info == FTS_DP \ + || (E)->fts_info == FTS_DNR) + enum RCH_status { /* we called fchown and close, and both succeeded */ @@ -351,7 +357,9 @@ change_file_owner (FTS *fts, FTSENT *ent, } /* This happens when chown -LR --preserve-root encounters a symlink-to-/. */ - if (ROOT_DEV_INO_CHECK (chopt->root_dev_ino, file_stats)) + if (ok + && FTSENT_IS_DIRECTORY (ent) + && ROOT_DEV_INO_CHECK (chopt->root_dev_ino, file_stats)) { ROOT_DEV_INO_WARN (file_full_name); return false; |