From: Jim Meyering Date: Mon, 26 Dec 2005 18:53:58 +0000 (+0000) Subject: (chdir_no_follow): Move declaration of local, X-Git-Tag: COREUTILS-6_0~1029 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=edf69af3173e70c4a0ce743a74d2313f37ebbbe8;p=platform%2Fupstream%2Fcoreutils.git (chdir_no_follow): Move declaration of local, 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. --- diff --git a/lib/chdir-safer.c b/lib/chdir-safer.c index 539eb2d..f6b42ce 100644 --- a/lib/chdir-safer.c +++ b/lib/chdir-safer.c @@ -45,9 +45,12 @@ /* 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)) {