From 3c640ae7a5cc33ab145404dc6d4926d93cbaed36 Mon Sep 17 00:00:00 2001
From: deraadt <>
Date: Fri, 5 Jul 2019 05:04:26 +0000
Subject: The last consumer of pre-posix realpath behaviour has stopped
 requiring it (sftp-server). Remove the /exists///// behaviour from here.  The
 /nonexistant behaviour remains in the kernel and needs to be shot next. There
 may be ports fallout, but we doubt it. ok beck djm

---
 src/lib/libc/stdlib/realpath.c | 37 +++----------------------------------
 1 file 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 @@
-/*	$OpenBSD: realpath.c,v 1.26 2019/06/17 03:13:17 deraadt Exp $ */
+/*	$OpenBSD: realpath.c,v 1.27 2019/07/05 05:04:26 deraadt Exp $ */
 /*
  * Copyright (c) 2019 Bob Beck <beck@openbsd.org>
  * Copyright (c) 2019 Theo de Raadt <deraadt@openbsd.org>
@@ -36,39 +36,8 @@ realpath(const char *path, char *resolved)
 {
 	char rbuf[PATH_MAX];
 
-	if (__realpath(path, rbuf) == -1) {
-		/*
-		 * XXX XXX XXX
-		 *
-		 * The old userland implementation strips trailing slashes.
-		 * According to Dr. POSIX, realpathing "/bsd" should be fine,
-		 * realpathing "/bsd/" should return ENOTDIR.
-		 *
-		 * Similar, but *different* to the above, The old userland
-		 * implementation allows for realpathing "/nonexistent" but
-		 * not "/nonexistent/", Both those should return ENOENT
-		 * according to POSIX.
-		 *
-		 * This hack should go away once we decide to match POSIX.
-		 * which we should as soon as is convenient.
-		 */
-		if (errno == ENOTDIR) {
-			char pbuf[PATH_MAX];
-			ssize_t i;
-
-			if (strlcpy(pbuf, path, sizeof(pbuf)) >= sizeof(pbuf)) {
-				errno = ENAMETOOLONG;
-				return NULL;
-			}
-			/* Try again without the trailing slashes. */
-			for (i = strlen(pbuf); i > 1 && pbuf[i - 1] == '/'; i--)
-				pbuf[i - 1] = '\0';
-			if (__realpath(pbuf, rbuf) == -1)
-				return NULL;
-		} else
-			return NULL;
-	}
-
+	if (__realpath(path, rbuf) == -1)
+		return NULL;
 	if (resolved == NULL)
 		return (strdup(rbuf));
 	strlcpy(resolved, rbuf, PATH_MAX);
-- 
cgit v1.2.3-55-g6feb