diff options
Diffstat (limited to 'lib/libc/stdlib/realpath.c')
-rw-r--r-- | lib/libc/stdlib/realpath.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/libc/stdlib/realpath.c b/lib/libc/stdlib/realpath.c index 28380d7..998ef57 100644 --- a/lib/libc/stdlib/realpath.c +++ b/lib/libc/stdlib/realpath.c @@ -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 (*p != '\0' && 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; |