diff options
| author | deraadt <> | 1997-06-20 20:37:45 +0000 |
|---|---|---|
| committer | deraadt <> | 1997-06-20 20:37:45 +0000 |
| commit | a95ecf3f30005b6b5d55131cfb166cf8e71e176d (patch) | |
| tree | fa59c607d355a682c852abaa3941cf3d16f44535 /src/lib/libc/stdlib/realpath.c | |
| parent | b7e803398762f20407d18ee6b1db343d595e6179 (diff) | |
| download | openbsd-a95ecf3f30005b6b5d55131cfb166cf8e71e176d.tar.gz openbsd-a95ecf3f30005b6b5d55131cfb166cf8e71e176d.tar.bz2 openbsd-a95ecf3f30005b6b5d55131cfb166cf8e71e176d.zip | |
add ELOOP support; shigio@wafu.netgate.net
Diffstat (limited to 'src/lib/libc/stdlib/realpath.c')
| -rw-r--r-- | src/lib/libc/stdlib/realpath.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/lib/libc/stdlib/realpath.c b/src/lib/libc/stdlib/realpath.c index 51e336efdd..78c286014d 100644 --- a/src/lib/libc/stdlib/realpath.c +++ b/src/lib/libc/stdlib/realpath.c | |||
| @@ -35,7 +35,7 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
| 38 | static char *rcsid = "$OpenBSD: realpath.c,v 1.2 1996/08/19 08:33:47 tholo Exp $"; | 38 | static char *rcsid = "$OpenBSD: realpath.c,v 1.3 1997/06/20 20:37:45 deraadt Exp $"; |
| 39 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
| 40 | 40 | ||
| 41 | #include <sys/param.h> | 41 | #include <sys/param.h> |
| @@ -62,6 +62,7 @@ realpath(path, resolved) | |||
| 62 | struct stat sb; | 62 | struct stat sb; |
| 63 | int fd, n, rootd, serrno; | 63 | int fd, n, rootd, serrno; |
| 64 | char *p, *q, wbuf[MAXPATHLEN]; | 64 | char *p, *q, wbuf[MAXPATHLEN]; |
| 65 | int symlinks = 0; | ||
| 65 | 66 | ||
| 66 | /* Save the starting point. */ | 67 | /* Save the starting point. */ |
| 67 | if ((fd = open(".", O_RDONLY)) < 0) { | 68 | if ((fd = open(".", O_RDONLY)) < 0) { |
| @@ -100,6 +101,10 @@ loop: | |||
| 100 | /* Deal with the last component. */ | 101 | /* Deal with the last component. */ |
| 101 | if (lstat(p, &sb) == 0) { | 102 | if (lstat(p, &sb) == 0) { |
| 102 | if (S_ISLNK(sb.st_mode)) { | 103 | if (S_ISLNK(sb.st_mode)) { |
| 104 | if (++symlinks > MAXSYMLINKS) { | ||
| 105 | errno = ELOOP; | ||
| 106 | goto err1; | ||
| 107 | } | ||
| 103 | n = readlink(p, resolved, MAXPATHLEN); | 108 | n = readlink(p, resolved, MAXPATHLEN); |
| 104 | if (n < 0) | 109 | if (n < 0) |
| 105 | goto err1; | 110 | goto err1; |
