This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH v2] Cygwin: normalize_win32_path: improve error checking
- From: Ken Brown <kbrown at cornell dot edu>
- To: "cygwin-patches at cygwin dot com" <cygwin-patches at cygwin dot com>
- Date: Thu, 26 Sep 2019 12:23:58 +0000
- Subject: [PATCH v2] Cygwin: normalize_win32_path: improve error checking
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cornell.edu; dmarc=pass action=none header.from=cornell.edu; dkim=pass header.d=cornell.edu; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ogRpONwSKYjgMg1i4j/9Evw1eU+/qbqtLnxDugx/XRM=; b=TDfU6Vu7hCY4Krh48zrUmdYDxDQABUE6ER8qS5pGN/dt47aZr9WuH+yYR7J6oqwxPaJABNWaqYJmRi4vBUIRFSpbbrNTE4/kPWa9IGkf3jpYiQtmS0m5Fjw9AcDWqxAEKkrg/0ZkCm7J5dOYpGFbWNWhosqYJb+7yPyvHixCzRAcxKTtkUOKe8VHANL3aT4InyP3cCIkZhRVmJkHhdk8MO6UqXBi/ga6RGh8unABUZ/gA7b8ic/dxSr5F3Dga3wxFUoZ3n0xvrvdy8PI5aTC0DdN5b7XZdRGvRYQQvDTgwW2izh5upPhlTSYwzNdOY0BxbAInyxmmS5UZ6uwZHqzHw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Om6JYnzDcHN1h3ZzoCO6fFzMvneQVJYdbxTF3OsanyF7mKiCKTLi10R3BE5f93z8hU7vlsG/HLLx89i6PARM4ZNsvIdok2z42CMUVwesT2vGkKoibARq/2GbUDUxzGVxIHtXb2iDi6TbxHajtc8H/SB/XAHmAcZ1XSRZ4HSOgwQCPNOrO9ZOOSMehodY1v62QiAjohmpuii9JhRWns3S5ymnfSGjqL2x6NKH0hOPIoMM4uYdygty1sKnn0iNsYqx6dLHoyJJc9h2eDYjMLFiOCL4REWuF9Wjn2lmmlXCEzuC0NjLFIRmdOoeDXGlIDwRtPp4EpQ+cKE8PLCBZc8OBg==
If the source path starts with the Win32 long path prefix '\\?\' or
the NT object directory prefix '\??\', require the prefix to be
followed by 'UNC\' or '<drive letter>:\'. Otherwise return EINVAL.
This fixes the assertion failure in symlink_info::check that was
reported here:
https://cygwin.com/ml/cygwin/2019-09/msg00228.html
That assertion failure was caused by normalize_win32_path returning a
path with no backslashes when the source path was '\\?\DRIVE'.
---
v2: use isdrive().
---
winsup/cygwin/path.cc | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 2fbacd881..f61003578 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -1406,15 +1406,18 @@ normalize_win32_path (const char *src, char *dst, char *&tail)
bool beg_src_slash = isdirsep (src[0]);
tail = dst;
- /* Skip long path name prefixes in Win32 or NT syntax. */
+ /* Skip Win32 long path name prefix and NT object directory prefix. */
if (beg_src_slash && (src[1] == '?' || isdirsep (src[1]))
&& src[2] == '?' && isdirsep (src[3]))
{
src += 4;
- if (src[1] != ':') /* native UNC path */
+ if (isdrive (src) && isdirsep (src[2]))
+ beg_src_slash = false;
+ else if (!strncmp (src, "UNC", 3) && isdirsep (src[3]))
+ /* native UNC path */
src += 2; /* Fortunately the first char is not copied... */
else
- beg_src_slash = false;
+ return EINVAL;
}
if (beg_src_slash && isdirsep (src[1]))
{
--
2.21.0