summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/realpath.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1997-07-16 11:25:48 +0000
committerphk <phk@FreeBSD.org>1997-07-16 11:25:48 +0000
commit1483aecd5e476d7a1d7b38ed7d075672b011eba9 (patch)
tree2b3d643f2b6be98b9b9847487aee13c0e88d78ef /lib/libc/stdlib/realpath.c
parent31e6d3aa835d3c658ad40d31b098449d9689ec77 (diff)
downloadFreeBSD-src-1483aecd5e476d7a1d7b38ed7d075672b011eba9.zip
FreeBSD-src-1483aecd5e476d7a1d7b38ed7d075672b011eba9.tar.gz
realpath() should break on looped symlinks.
PR: 3911 Reviewed by: phk Submitted by: Shigio Yamaguchi <shigio@wafu.netgate.net>
Diffstat (limited to 'lib/libc/stdlib/realpath.c')
-rw-r--r--lib/libc/stdlib/realpath.c5
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;
OpenPOWER on IntegriCloud