diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libc/stdlib/realpath.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/lib/libc/stdlib/realpath.c b/src/lib/libc/stdlib/realpath.c index 8c83ec2b81..e06db59088 100644 --- a/src/lib/libc/stdlib/realpath.c +++ b/src/lib/libc/stdlib/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 | * |
| @@ -54,10 +54,6 @@ realpath(const char *path, char *resolved) | |||
| 54 | int serrno, slen, mem_allocated; | 54 | int serrno, slen, mem_allocated; |
| 55 | char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX]; | 55 | char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX]; |
| 56 | 56 | ||
| 57 | if (path == NULL) { | ||
| 58 | errno = EINVAL; | ||
| 59 | return (NULL); | ||
| 60 | } | ||
| 61 | if (path[0] == '\0') { | 57 | if (path[0] == '\0') { |
| 62 | errno = ENOENT; | 58 | errno = ENOENT; |
| 63 | return (NULL); | 59 | return (NULL); |
| @@ -143,15 +139,22 @@ realpath(const char *path, char *resolved) | |||
| 143 | } | 139 | } |
| 144 | 140 | ||
| 145 | /* | 141 | /* |
| 146 | * Append the next path component and lstat() it. | 142 | * Append the next path component and lstat() it. If |
| 143 | * lstat() fails we still can return successfully if | ||
| 144 | * there are no more path components left. | ||
| 147 | */ | 145 | */ |
| 148 | resolved_len = strlcat(resolved, next_token, PATH_MAX); | 146 | resolved_len = strlcat(resolved, next_token, PATH_MAX); |
| 149 | if (resolved_len >= PATH_MAX) { | 147 | if (resolved_len >= PATH_MAX) { |
| 150 | errno = ENAMETOOLONG; | 148 | errno = ENAMETOOLONG; |
| 151 | goto err; | 149 | goto err; |
| 152 | } | 150 | } |
| 153 | if (lstat(resolved, &sb) != 0) | 151 | if (lstat(resolved, &sb) != 0) { |
| 152 | if (errno == ENOENT && p == NULL) { | ||
| 153 | errno = serrno; | ||
| 154 | return (resolved); | ||
| 155 | } | ||
| 154 | goto err; | 156 | goto err; |
| 157 | } | ||
| 155 | if (S_ISLNK(sb.st_mode)) { | 158 | if (S_ISLNK(sb.st_mode)) { |
| 156 | if (symlinks++ > MAXSYMLINKS) { | 159 | if (symlinks++ > MAXSYMLINKS) { |
| 157 | errno = ELOOP; | 160 | errno = ELOOP; |
| @@ -193,9 +196,6 @@ realpath(const char *path, char *resolved) | |||
| 193 | } | 196 | } |
| 194 | } | 197 | } |
| 195 | left_len = strlcpy(left, symlink, sizeof(left)); | 198 | left_len = strlcpy(left, symlink, sizeof(left)); |
| 196 | } else if (!S_ISDIR(sb.st_mode) && p != NULL) { | ||
| 197 | errno = ENOTDIR; | ||
| 198 | goto err; | ||
| 199 | } | 199 | } |
| 200 | } | 200 | } |
| 201 | 201 | ||
