diff options
Diffstat (limited to 'src/lib/libc')
| -rw-r--r-- | src/lib/libc/stdlib/realpath.c | 37 |
1 files changed, 3 insertions, 34 deletions
diff --git a/src/lib/libc/stdlib/realpath.c b/src/lib/libc/stdlib/realpath.c index 0d44430d05..f7ac9fe606 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.26 2019/06/17 03:13:17 deraadt Exp $ */ | 1 | /* $OpenBSD: realpath.c,v 1.27 2019/07/05 05:04:26 deraadt Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2019 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2019 Bob Beck <beck@openbsd.org> |
| 4 | * Copyright (c) 2019 Theo de Raadt <deraadt@openbsd.org> | 4 | * Copyright (c) 2019 Theo de Raadt <deraadt@openbsd.org> |
| @@ -36,39 +36,8 @@ realpath(const char *path, char *resolved) | |||
| 36 | { | 36 | { |
| 37 | char rbuf[PATH_MAX]; | 37 | char rbuf[PATH_MAX]; |
| 38 | 38 | ||
| 39 | if (__realpath(path, rbuf) == -1) { | 39 | if (__realpath(path, rbuf) == -1) |
| 40 | /* | 40 | return NULL; |
| 41 | * XXX XXX XXX | ||
| 42 | * | ||
| 43 | * The old userland implementation strips trailing slashes. | ||
| 44 | * According to Dr. POSIX, realpathing "/bsd" should be fine, | ||
| 45 | * realpathing "/bsd/" should return ENOTDIR. | ||
| 46 | * | ||
| 47 | * Similar, but *different* to the above, The old userland | ||
| 48 | * implementation allows for realpathing "/nonexistent" but | ||
| 49 | * not "/nonexistent/", Both those should return ENOENT | ||
| 50 | * according to POSIX. | ||
| 51 | * | ||
| 52 | * This hack should go away once we decide to match POSIX. | ||
| 53 | * which we should as soon as is convenient. | ||
| 54 | */ | ||
| 55 | if (errno == ENOTDIR) { | ||
| 56 | char pbuf[PATH_MAX]; | ||
| 57 | ssize_t i; | ||
| 58 | |||
| 59 | if (strlcpy(pbuf, path, sizeof(pbuf)) >= sizeof(pbuf)) { | ||
| 60 | errno = ENAMETOOLONG; | ||
| 61 | return NULL; | ||
| 62 | } | ||
| 63 | /* Try again without the trailing slashes. */ | ||
| 64 | for (i = strlen(pbuf); i > 1 && pbuf[i - 1] == '/'; i--) | ||
| 65 | pbuf[i - 1] = '\0'; | ||
| 66 | if (__realpath(pbuf, rbuf) == -1) | ||
| 67 | return NULL; | ||
| 68 | } else | ||
| 69 | return NULL; | ||
| 70 | } | ||
| 71 | |||
| 72 | if (resolved == NULL) | 41 | if (resolved == NULL) |
| 73 | return (strdup(rbuf)); | 42 | return (strdup(rbuf)); |
| 74 | strlcpy(resolved, rbuf, PATH_MAX); | 43 | strlcpy(resolved, rbuf, PATH_MAX); |
