diff options
Diffstat (limited to 'src/lib/libc/stdlib/realpath.c')
-rw-r--r-- | src/lib/libc/stdlib/realpath.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/lib/libc/stdlib/realpath.c b/src/lib/libc/stdlib/realpath.c index e349b7e068..0288601464 100644 --- a/src/lib/libc/stdlib/realpath.c +++ b/src/lib/libc/stdlib/realpath.c | |||
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
38 | /*static char sccsid[] = "from: @(#)realpath.c 8.1 (Berkeley) 2/16/94";*/ | 38 | static char *rcsid = "$OpenBSD: realpath.c,v 1.4 1998/05/18 09:55:19 deraadt Exp $"; |
39 | static char *rcsid = "$Id: realpath.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
41 | 40 | ||
42 | #include <sys/param.h> | 41 | #include <sys/param.h> |
@@ -63,6 +62,7 @@ realpath(path, resolved) | |||
63 | struct stat sb; | 62 | struct stat sb; |
64 | int fd, n, rootd, serrno; | 63 | int fd, n, rootd, serrno; |
65 | char *p, *q, wbuf[MAXPATHLEN]; | 64 | char *p, *q, wbuf[MAXPATHLEN]; |
65 | int symlinks = 0; | ||
66 | 66 | ||
67 | /* Save the starting point. */ | 67 | /* Save the starting point. */ |
68 | if ((fd = open(".", O_RDONLY)) < 0) { | 68 | if ((fd = open(".", O_RDONLY)) < 0) { |
@@ -101,7 +101,11 @@ loop: | |||
101 | /* Deal with the last component. */ | 101 | /* Deal with the last component. */ |
102 | if (lstat(p, &sb) == 0) { | 102 | if (lstat(p, &sb) == 0) { |
103 | if (S_ISLNK(sb.st_mode)) { | 103 | if (S_ISLNK(sb.st_mode)) { |
104 | n = readlink(p, resolved, MAXPATHLEN); | 104 | if (++symlinks > MAXSYMLINKS) { |
105 | errno = ELOOP; | ||
106 | goto err1; | ||
107 | } | ||
108 | n = readlink(p, resolved, MAXPATHLEN-1); | ||
105 | if (n < 0) | 109 | if (n < 0) |
106 | goto err1; | 110 | goto err1; |
107 | resolved[n] = '\0'; | 111 | resolved[n] = '\0'; |