diff options
author | Jim Meyering <jim@meyering.net> | 2004-07-07 15:54:51 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2004-07-07 15:54:51 +0000 |
commit | f1314a409c320ca57947e8a624ce857e12051c62 (patch) | |
tree | 025f7f631d0a9a18afbd0f8278826f0dd966ae2d | |
parent | ff5ea922714b555de3554691d90f526ef8ad849a (diff) | |
download | coreutils-f1314a409c320ca57947e8a624ce857e12051c62.tar.xz |
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.
-rw-r--r-- | lib/canonicalize.c | 8 |
1 files changed, 4 insertions, 4 deletions
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 <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 *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) |