bug-glibc
[Top][All Lists]
Advanced

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

two bugs in io/fts.c


From: Jim Meyering
Subject: two bugs in io/fts.c
Date: Mon, 24 Feb 2003 00:55:14 +0100

Although I found the fts_open bug by inspection, I have since confirmed
that the same patch is also in at least the latest NetBSD sources.
The latter hunk however is not.

Without the latter change, even though fts_errno *is* set,
the caller of fts cannot detect its failure to change into
an inaccessible subdirectory, since ->fts_info suggests
there is no error.

I have some more changes for fts.[ch]:

  * make it portable to non-glibc systems
  * convert the O(N^2) cycle-detection code to be O(NlogN)
      (this requires adding a member to the FTS struct)
  * remove some limitations (e.g., max depth is 32767 levels)
      imposed by the use of 16-bit types in fts.h

How do you feel about changing the sizes of structure members
in fts.h?  If it's not possible to change them in glibc,
please let me know, and I won't waste time preparing the patch.

Also, I plan to merge in some of the changes from the *bsd
development code.

Yes, fts needs a test harness, maybe something like the one for ftw.

2003-02-24  Jim Meyering  <address@hidden>

        * io/fts.c: (fts_open): If fts_alloc returns NULL, don't dereference it.
        (fts_read): If fts_safe_changedir fails because it is not
        able to chdir into a subdirectory, then inform the caller.

Index: fts.c
===================================================================
RCS file: /cvs/glibc/libc/io/fts.c,v
retrieving revision 1.26
diff -u -p -u -p -r1.26 fts.c
--- fts.c       29 Dec 2001 21:06:47 -0000      1.26
+++ fts.c       23 Feb 2003 23:35:14 -0000
@@ -136,7 +136,8 @@ fts_open(argv, options, compar)
                        goto mem3;
                }
 
-               p = fts_alloc(sp, *argv, len);
+               if ((p = fts_alloc(sp, *argv, len)) == NULL)
+                       goto mem3;
                p->fts_level = FTS_ROOTLEVEL;
                p->fts_parent = parent;
                p->fts_accpath = p->fts_name;
@@ -369,6 +370,11 @@ fts_read(sp)
                } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
                        if (ISSET(FTS_STOP))
                                return (NULL);
+                       /* If fts_build's call to fts_safe_changedir failed
+                          because it was not able to fchdir into a
+                          subdirectory, tell the caller.  */
+                       if (p->fts_errno)
+                               p->fts_info = FTS_ERR;
                        return (p);
                }
                p = sp->fts_child;

Attachment: pgpFNB69uCFAD.pgp
Description: PGP signature


reply via email to

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