summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2019-07-09 17:30:40 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2019-07-09 17:30:40 +0000
commit27bda5ef232824a450c7e412b3d22cae11ad7a62 (patch)
tree58cdf5188e04442dc10d3039cdae944670358499 /regress
parentb0363652e17c04452aeb2b30c1d11cafcb6d1001 (diff)
Regress realpath(3) fails since the non directory hack has been
removed from libc. Make the regress implementation more POSIX compliant like it has been done for the kernel. OK beck@ deraadt@
Diffstat (limited to 'regress')
-rw-r--r--regress/sys/kern/realpath/realpath3.c18
-rw-r--r--regress/sys/kern/realpath/realpathtest.c4
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] = '.';