summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-06-20 20:37:46 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-06-20 20:37:46 +0000
commit6c1e24c665b190ea0e52e43efafd616aa6ff6e51 (patch)
tree173c27872a19bd02d0c701b5a8a5453114ccd77b /lib/libc/stdlib
parentdb2c002aa4938b70a4f8fc0ab5c7247693c1bf6b (diff)
add ELOOP support; shigio@wafu.netgate.net
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/realpath.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/libc/stdlib/realpath.c b/lib/libc/stdlib/realpath.c
index 51e336efdd5..78c286014dc 100644
--- a/lib/libc/stdlib/realpath.c
+++ b/lib/libc/stdlib/realpath.c
@@ -35,7 +35,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: realpath.c,v 1.2 1996/08/19 08:33:47 tholo Exp $";
+static char *rcsid = "$OpenBSD: realpath.c,v 1.3 1997/06/20 20:37:45 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -62,6 +62,7 @@ realpath(path, resolved)
struct stat sb;
int fd, n, rootd, serrno;
char *p, *q, wbuf[MAXPATHLEN];
+ int symlinks = 0;
/* Save the starting point. */
if ((fd = open(".", O_RDONLY)) < 0) {
@@ -100,6 +101,10 @@ loop:
/* Deal with the last component. */
if (lstat(p, &sb) == 0) {
if (S_ISLNK(sb.st_mode)) {
+ if (++symlinks > MAXSYMLINKS) {
+ errno = ELOOP;
+ goto err1;
+ }
n = readlink(p, resolved, MAXPATHLEN);
if (n < 0)
goto err1;