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 3ac7d123e5e6ca106ad02adb58cc497253e3bd81..cd31557fb5b53463d9efbb7954e14ceae575428f 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 7616c6fc138eaedba9410573a86f5ca235bccc1b..ebf66fc45f9f46c5d53ebe27cd29037a6bd97df6 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)