From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2210) id A61B6386EC6C; Fri, 22 Jan 2021 15:44:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A61B6386EC6C Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Ken Brown To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: normalize_posix_path: fix error handling when .. is encountered X-Act-Checkin: newlib-cygwin X-Git-Author: Ken Brown X-Git-Refname: refs/heads/master X-Git-Oldrev: 0c0ff5dc2103988bda9eee2a97633a8b54bb476e X-Git-Newrev: 4aefad2bb827afa273fcd768bd06dd618d41ae75 Message-Id: <20210122154431.A61B6386EC6C@sourceware.org> Date: Fri, 22 Jan 2021 15:44:31 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jan 2021 15:44:31 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=4aefad2bb827afa273fcd768bd06dd618d41ae75 commit 4aefad2bb827afa273fcd768bd06dd618d41ae75 Author: Ken Brown Date: Wed Jan 20 10:12:58 2021 -0500 Cygwin: normalize_posix_path: fix error handling when .. is encountered When .. is in the source path and the path prefix exists but is not a directory, return ENOTDIR instead of ENOENT. This fixes a POSIX compliance issue for realpath(3): https://pubs.opengroup.org/onlinepubs/9699919799/functions/realpath.html Addresses: https://lists.gnu.org/archive/html/bug-gnulib/2021-01/msg00214.html Diff: --- winsup/cygwin/path.cc | 4 +++- winsup/cygwin/release/3.2.0 | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index abd3687df..6dc162806 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -323,8 +323,10 @@ normalize_posix_path (const char *src, char *dst, char *&tail) if (!tp.check_usage (4, 3)) return ELOOP; path_conv head (dst, PC_SYM_FOLLOW | PC_POSIX); - if (!head.isdir()) + if (!head.exists ()) return ENOENT; + if (!head.isdir ()) + return ENOTDIR; /* At this point, dst is a normalized path. If the normalized path created by path_conv does not match the normalized path we're just testing, then diff --git a/winsup/cygwin/release/3.2.0 b/winsup/cygwin/release/3.2.0 index c18a848de..43725cec2 100644 --- a/winsup/cygwin/release/3.2.0 +++ b/winsup/cygwin/release/3.2.0 @@ -48,3 +48,7 @@ Bug Fixes - Fix a bug in fstatat(2) on 32 bit that could cause it to return garbage. Addresses: https://cygwin.com/pipermail/cygwin/2021-January/247399.html + +- Fix the errno when a path contains .. and the prefix exists but is + not a directory. + Addresses: https://lists.gnu.org/archive/html/bug-gnulib/2021-01/msg00214.html