diff options
-rw-r--r-- | openbsd-compat/realpath.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/openbsd-compat/realpath.c b/openbsd-compat/realpath.c index d2f34dde0..e4729a808 100644 --- a/openbsd-compat/realpath.c +++ b/openbsd-compat/realpath.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: realpath.c,v 1.17 2014/10/18 20:43:52 doug Exp $ */ | 1 | /* $OpenBSD: realpath.c,v 1.18 2014/10/19 03:56:28 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,10 +62,6 @@ 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 | } | ||
69 | if (path[0] == '\0') { | 65 | if (path[0] == '\0') { |
70 | errno = ENOENT; | 66 | errno = ENOENT; |
71 | return (NULL); | 67 | return (NULL); |
@@ -151,15 +147,22 @@ realpath(const char *path, char *resolved) | |||
151 | } | 147 | } |
152 | 148 | ||
153 | /* | 149 | /* |
154 | * Append the next path component and lstat() it. | 150 | * Append the next path component and lstat() it. If |
151 | * lstat() fails we still can return successfully if | ||
152 | * there are no more path components left. | ||
155 | */ | 153 | */ |
156 | resolved_len = strlcat(resolved, next_token, PATH_MAX); | 154 | resolved_len = strlcat(resolved, next_token, PATH_MAX); |
157 | if (resolved_len >= PATH_MAX) { | 155 | if (resolved_len >= PATH_MAX) { |
158 | errno = ENAMETOOLONG; | 156 | errno = ENAMETOOLONG; |
159 | goto err; | 157 | goto err; |
160 | } | 158 | } |
161 | if (lstat(resolved, &sb) != 0) | 159 | if (lstat(resolved, &sb) != 0) { |
160 | if (errno == ENOENT && p == NULL) { | ||
161 | errno = serrno; | ||
162 | return (resolved); | ||
163 | } | ||
162 | goto err; | 164 | goto err; |
165 | } | ||
163 | if (S_ISLNK(sb.st_mode)) { | 166 | if (S_ISLNK(sb.st_mode)) { |
164 | if (symlinks++ > MAXSYMLINKS) { | 167 | if (symlinks++ > MAXSYMLINKS) { |
165 | errno = ELOOP; | 168 | errno = ELOOP; |
@@ -202,9 +205,6 @@ realpath(const char *path, char *resolved) | |||
202 | } | 205 | } |
203 | } | 206 | } |
204 | left_len = strlcpy(left, symlink, sizeof(left)); | 207 | 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 | ||