bug-coreutils
[Top][All Lists]
Advanced

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

FYI: canonicalize.c fix, affects readlink -f and new -e and -m options


From: Jim Meyering
Subject: FYI: canonicalize.c fix, affects readlink -f and new -e and -m options
Date: Wed, 07 Jul 2004 17:54:39 +0200

I've just checked in this fix:

2004-07-07  Jim Meyering  <address@hidden>

        Don't infloop when MAXSYMLINKS is not defined.
        Detect symlink loops much earlier (albeit lazily) on systems
        with MAXSYMLINKS defined to a large value.

        * canonicalize.c: Include "cycle-check.h".
        (canonicalize_filename_mode): Don't try to detect loops by counting
        symlink-hops.  Instead, use the cycle-check module.

Index: lib/canonicalize.c
===================================================================
RCS file: /fetish/cu/lib/canonicalize.c,v
retrieving revision 1.16
diff -u -p -r1.16 canonicalize.c
--- lib/canonicalize.c  7 Jul 2004 09:28:15 -0000       1.16
+++ lib/canonicalize.c  7 Jul 2004 15:05:42 -0000
@@ -44,6 +44,7 @@ void free ();
 
 #include <errno.h>
 
+#include "cycle-check.h"
 #include "path-concat.h"
 #include "stat-macros.h"
 #include "xalloc.h"
@@ -164,7 +165,7 @@ canonicalize_filename_mode (const char *
   char *rpath, *dest, *extra_buf = NULL;
   const char *start, *end, *rpath_limit;
   size_t extra_len = 0;
-  int num_links = 0;
+  struct cycle_check_state cycle_state;
 
   if (name == NULL)
     {
@@ -204,6 +205,7 @@ canonicalize_filename_mode (const char *
       dest = rpath + 1;
     }
 
+  cycle_check_init (&cycle_state);
   for (start = end = name; *start; start = end)
     {
       /* Skip sequence of multiple path-separators.  */
@@ -264,8 +266,7 @@ canonicalize_filename_mode (const char *
              char *buf;
              size_t n, len;
 
-#  ifdef MAXSYMLINKS
-             if (++num_links > MAXSYMLINKS)
+             if (cycle_check (&cycle_state, &st))
                {
                  __set_errno (ELOOP);
                  if (can_mode == CAN_MISSING)
@@ -273,7 +274,6 @@ canonicalize_filename_mode (const char *
                  else
                    goto error;
                }
-#  endif /* MAXSYMLINKS */
 
              buf = xreadlink (rpath, st.st_size);
              if (!buf)




reply via email to

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