summaryrefslogtreecommitdiff
path: root/openbsd-compat/realpath.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2015-10-14 08:26:24 +1100
committerDamien Miller <djm@mindrot.org>2015-10-14 08:26:24 +1100
commitc39ad23b06e9aecc3ff788e92f787a08472905b1 (patch)
treee45f5c5c279a5df9543b7528f59e46353b5fccf6 /openbsd-compat/realpath.c
parente929a43f957dbd1254aca2aaf85c8c00cbfc25f4 (diff)
upstream commit
revision 1.17 date: 2014/10/18 20:43:52; author: doug; state: Exp; lines: +10 -10; commitid: I74hI1tVZtsspKEt; Better POSIX compliance in realpath(3). millert@ made changes to realpath.c based on FreeBSD's version. I merged Todd's changes into dl_realpath.c. ok millert@, guenther@
Diffstat (limited to 'openbsd-compat/realpath.c')
-rw-r--r--openbsd-compat/realpath.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/openbsd-compat/realpath.c b/openbsd-compat/realpath.c
index a954b1b7a..d2f34dde0 100644
--- a/openbsd-compat/realpath.c
+++ b/openbsd-compat/realpath.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: realpath.c,v 1.16 2013/04/05 12:59:54 kurt Exp $ */ 1/* $OpenBSD: realpath.c,v 1.17 2014/10/18 20:43:52 doug Exp $ */
2/* 2/*
3 * Copyright (c) 2003 Constantin S. Svintsoff <kostik@iclub.nsu.ru> 3 * Copyright (c) 2003 Constantin S. Svintsoff <kostik@iclub.nsu.ru>
4 * 4 *
@@ -62,6 +62,10 @@ realpath(const char *path, char *resolved)
62 int serrno, slen, mem_allocated; 62 int serrno, slen, mem_allocated;
63 char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX]; 63 char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX];
64 64
65 if (path == NULL) {
66 errno = EINVAL;
67 return (NULL);
68 }
65 if (path[0] == '\0') { 69 if (path[0] == '\0') {
66 errno = ENOENT; 70 errno = ENOENT;
67 return (NULL); 71 return (NULL);
@@ -147,22 +151,15 @@ realpath(const char *path, char *resolved)
147 } 151 }
148 152
149 /* 153 /*
150 * Append the next path component and lstat() it. If 154 * Append the next path component and lstat() it.
151 * lstat() fails we still can return successfully if
152 * there are no more path components left.
153 */ 155 */
154 resolved_len = strlcat(resolved, next_token, PATH_MAX); 156 resolved_len = strlcat(resolved, next_token, PATH_MAX);
155 if (resolved_len >= PATH_MAX) { 157 if (resolved_len >= PATH_MAX) {
156 errno = ENAMETOOLONG; 158 errno = ENAMETOOLONG;
157 goto err; 159 goto err;
158 } 160 }
159 if (lstat(resolved, &sb) != 0) { 161 if (lstat(resolved, &sb) != 0)
160 if (errno == ENOENT && p == NULL) {
161 errno = serrno;
162 return (resolved);
163 }
164 goto err; 162 goto err;
165 }
166 if (S_ISLNK(sb.st_mode)) { 163 if (S_ISLNK(sb.st_mode)) {
167 if (symlinks++ > MAXSYMLINKS) { 164 if (symlinks++ > MAXSYMLINKS) {
168 errno = ELOOP; 165 errno = ELOOP;
@@ -205,6 +202,9 @@ realpath(const char *path, char *resolved)
205 } 202 }
206 } 203 }
207 left_len = strlcpy(left, symlink, sizeof(left)); 204 left_len = strlcpy(left, symlink, sizeof(left));
205 } else if (!S_ISDIR(sb.st_mode) && p != NULL) {
206 errno = ENOTDIR;
207 goto err;
208 } 208 }
209 } 209 }
210 210