fts: make directory fds more robust
authorEric Blake <ebb9@byu.net>
Tue, 1 Sep 2009 20:06:37 +0000 (14:06 -0600)
committerEric Blake <ebb9@byu.net>
Thu, 3 Sep 2009 02:34:41 +0000 (20:34 -0600)
* lib/fts.c (O_DIRECTORY): Let <fcntl.h> take care of this.
(opendirat): Specify O_DIRECTORY, and add fallbacks for safety.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/fts.c

index 3ac7d12..cd31557 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-09-02  Eric Blake  <ebb9@byu.net>
 
+       fts: make directory fds more robust
+       * lib/fts.c (O_DIRECTORY): Let <fcntl.h> take care of this.
+       (opendirat): Specify O_DIRECTORY, and add fallbacks for safety.
+
        backupfile, chdir-long, fts, savedir: make safer
        * lib/backupfile.c (includes): Use "dirent--.h", since
        numbered_backup can write to stderr during readdir.
index 7616c6f..ebf66fc 100644 (file)
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -228,10 +228,6 @@ static void free_dir (FTS *fts) {}
 # define SIZE_MAX ((size_t) -1)
 #endif
 
-#ifndef O_DIRECTORY
-# define O_DIRECTORY 0
-#endif
-
 #define ISDOT(a)       (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
 #define STREQ(a, b)    (strcmp ((a), (b)) == 0)
 
@@ -309,7 +305,8 @@ static inline DIR *
 internal_function
 opendirat (int fd, char const *dir)
 {
-  int new_fd = openat (fd, dir, O_RDONLY);
+  int new_fd = openat (fd, dir,
+                      O_RDONLY | O_DIRECTORY | O_NOCTTY | O_NONBLOCK);
   DIR *dirp;
 
   if (new_fd < 0)