(chdir_no_follow): Move declaration of local,
authorJim Meyering <jim@meyering.net>
Mon, 26 Dec 2005 18:53:58 +0000 (18:53 +0000)
committerJim Meyering <jim@meyering.net>
Mon, 26 Dec 2005 18:53:58 +0000 (18:53 +0000)
sb2, `down' into the scope where it is used.
Note that on some systems this function also fails when DIR
is a writable-yet-unreadable directory.

lib/chdir-safer.c

index 539eb2d..f6b42ce 100644 (file)
 
 /* Like chdir, but fail if DIR is a symbolic link to a directory (or
    similar funny business), or if DIR is neither readable nor
-   writeable.  This avoids a minor race condition between when a
-   directory is created or statted and when the process chdirs into
-   it.  */
+   writable.  This avoids a minor race condition between when a
+   directory is created or statted and when the process chdirs into it.
+
+   On some systems, a writable yet unreadable directory cannot be
+   opened via open with O_WRONLY.  For example, on Linux 2.6, the
+   open syscall fails with EISDIR.  */
 int
 chdir_no_follow (char const *dir)
 {
@@ -70,11 +73,10 @@ chdir_no_follow (char const *dir)
   if (! O_NOFOLLOW)
     {
       struct stat sb1;
-      struct stat sb2;
-
       result = lstat (dir, &sb1);
       if (result == 0)
        {
+         struct stat sb2;
          result = fstat (fd, &sb2);
          if (result == 0 && ! SAME_INODE (sb1, sb2))
            {