From f1314a409c320ca57947e8a624ce857e12051c62 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 7 Jul 2004 15:54:51 +0000 Subject: Don't infloop when MAXSYMLINKS is not defined. Detect symlink loops much earlier (albeit lazily) on systems with MAXSYMLINKS defined to a large value. Include "cycle-check.h". (canonicalize_filename_mode): Don't try to detect loops by counting symlink-hops. Instead, use the cycle-check module. --- lib/canonicalize.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/canonicalize.c b/lib/canonicalize.c index b406aa456..02bea7c5a 100644 --- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -44,6 +44,7 @@ void free (); #include +#include "cycle-check.h" #include "path-concat.h" #include "stat-macros.h" #include "xalloc.h" @@ -164,7 +165,7 @@ canonicalize_filename_mode (const char *name, canonicalize_mode_t can_mode) 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 *name, canonicalize_mode_t can_mode) 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 *name, canonicalize_mode_t can_mode) 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 *name, canonicalize_mode_t can_mode) else goto error; } -# endif /* MAXSYMLINKS */ buf = xreadlink (rpath, st.st_size); if (!buf) -- cgit v1.2.3-70-g09d2