summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2007-01-10 22:00:44 +0100
committerJim Meyering <jim@meyering.net>2007-01-10 22:00:44 +0100
commitb5f1873022d7abc93313df2dfd16d8aa58119916 (patch)
tree63ea596a2d40860cbf6211285e9a6891e2359010
parentdad7d86d57d2a6351ba1a395109760dce8977a91 (diff)
downloadcoreutils-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--ChangeLog8
-rw-r--r--src/chown-core.c12
2 files changed, 18 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index d4e766ed3..a89a0165e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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;