bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug in chdir-safer


From: Jim Meyering
Subject: Re: bug in chdir-safer
Date: Mon, 26 Dec 2005 20:01:05 +0100

Paul Eggert <address@hidden> wrote:
> Jim Meyering <address@hidden> writes:
>
>>      * chdir-safer.c (chdir_no_follow): Remove unnecessary
>>      test of S_ISDIR (sb_init.st_mode).
>
> I had noticed that problem along with some others with chdir-safer.c.
> I installed the following patch to clean up the other issues I saw.

Thanks!
I recognize the value of the added open-with-O_WRONLY,
but note that it's wasted on modern Linux systems.

I've checked in one more little change:

2005-12-26  Jim Meyering  <address@hidden>

        * chdir-safer.c (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.

Index: lib/chdir-safer.c
===================================================================
RCS file: /fetish/cu/lib/chdir-safer.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -p -u -r1.6 -r1.7
--- lib/chdir-safer.c   25 Dec 2005 21:38:43 -0000      1.6
+++ lib/chdir-safer.c   26 Dec 2005 18:53:58 -0000      1.7
@@ -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))
            {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]