diff options
Diffstat (limited to 'regress')
-rw-r--r-- | regress/sys/kern/realpath/realpath3.c | 18 | ||||
-rw-r--r-- | regress/sys/kern/realpath/realpathtest.c | 4 |
2 files changed, 19 insertions, 3 deletions
diff --git a/regress/sys/kern/realpath/realpath3.c b/regress/sys/kern/realpath/realpath3.c index 6e0d2a204d2..ffa606af736 100644 --- a/regress/sys/kern/realpath/realpath3.c +++ b/regress/sys/kern/realpath/realpath3.c @@ -1,4 +1,4 @@ -/* $OpenBSD: realpath3.c,v 1.1 2019/04/19 19:50:48 beck Exp $ */ +/* $OpenBSD: realpath3.c,v 1.2 2019/07/09 17:30:39 bluhm Exp $ */ /* * Copyright (c) 2003 Constantin S. Svintsoff <kostik@iclub.nsu.ru> * @@ -27,6 +27,8 @@ * SUCH DAMAGE. */ +#include <sys/stat.h> + #include <errno.h> #include <stdlib.h> #include <string.h> @@ -36,6 +38,8 @@ /* * The OpenBSD 6.4 libc version of realpath(3), preserved to validate * an implementation of realpath(2). + * As our kernel realpath(2) is heading towards to POSIX compliance, + * some details in this version have changed. */ /* @@ -222,6 +226,18 @@ realpath3(const char *path, char *resolved) } /* + * POSIX demands ENOTDIR for non directories ending in a "/". + */ + if (strchr(path, '/') != NULL && path[strlen(path) - 1] == '/') { + struct stat sb; + + if (stat(resolved, &sb) != -1 && !S_ISDIR(sb.st_mode)) { + errno = ENOTDIR; + goto err; + } + } + + /* * Remove trailing slash except when the resolved pathname * is a single "/". */ diff --git a/regress/sys/kern/realpath/realpathtest.c b/regress/sys/kern/realpath/realpathtest.c index a6d06057c92..cb89f649839 100644 --- a/regress/sys/kern/realpath/realpathtest.c +++ b/regress/sys/kern/realpath/realpathtest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: realpathtest.c,v 1.8 2019/07/09 17:00:12 bluhm Exp $ */ +/* $OpenBSD: realpathtest.c,v 1.9 2019/07/09 17:30:39 bluhm Exp $ */ /* * Copyright (c) 2019 Bob Beck <beck@openbsd.org> @@ -153,7 +153,7 @@ main(int argc, char *argv[]) } i-= 3; strlcpy(big+i, "bsd/", 5); - RP_SHOULD_SUCCEED(big, r2, r3); /* XXX This is wrong by posix */ + RP_SHOULD_FAIL(big, r2, r3); for (i = 0; i < (PATH_MAX - 5); i += 3) { big[i] = '.'; |