This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH] 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: Wed, 25 Sep 2019 18:47:11 +0000
- Subject: [PATCH] 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=CNjDwN4FL71ZoexTR8wbA0TiL0muZ1DlfL8W1O9u5kQ=; b=jbpdYF7+CupoJ32guHMcfX5ul1zjdkoX3DW85yIVVz19S6yxaDhOZ/OWIbbrjvGoHV/obfbHTiQnz+E2p8EChg61ha+OCOHolxFfGm2HWeNgFkvKy9LRWwLQJHGvMAnkC02Cq/pdh1T8u6JFazRrljMMvEQI26ZNb8i4P1pijGnJ0GqK+Sy9xSfOKlJaZCMGKQdh3DCehmrWu1SSKHWEwcGneLMFNxnZ2YJG1h/PqgyjzgnY0QM2XxHFtrHg1qiw00FgVfVBoZpXftaXpPf8XN+ehfvSwEpQYGf8PGvibhxD8m8I2LhfV11yResksunDAy2paM+nUPWl7ZxWmz6cjg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IDPRJaO2L+9i3VeLd86DeGoe5AzpCxUVa7Bi8x1GgXOOGE+qzpHZ2mK2Zf5Pnt8bYypJoMXdLLGJoig8HrFxdA1Yq7BPzBesB0FWwexZiGgX80lE5Tc+2ibE5f8FlT33vh+ZhEXe9NM0PmfBO69hz4r6ofVg4ews6rDttCMwxTZjoWVDcoqyuVlyiKn7N9j59d/ndb6in37HoHo29RFMxlKRTJd77mBM2hB6NrP39LVjaOjqX05zRBQTA9lw/WNPO3Bv9BNr4D7oQQgg8z65YAKugFIvBnb0wgRDQpm2fNntEa/G2tyhqRl90vP6i9Ts+sbGAT5fPf2OX8FksPW5gA==
If the src 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 input src path was '\\?\DRIVE'.
---
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..2eeb4fd1c 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 (src[1] == ':' && 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