public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH v2] Cygwin: path: Add fallback for DFS mounted drive.
@ 2022-03-14 10:57 Takashi Yano
  2022-03-14 11:04 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Takashi Yano @ 2022-03-14 10:57 UTC (permalink / raw)
  To: cygwin-patches

- If UNC path for DFS is mounted to a drive with drive letter, the
  error "Too many levels of symbolic links" occurs when accessing
  to that drive. This is because GetDosDeviceW() returns unexpected
  string such as "\Device\Mup\DfsClient\;Z:000000000003fb89\dfsserver
  \dfs\linkname" for the mounted UNC path "\??\UNC\fileserver\share".
  This patch adds a workaround for this issue.

  Addresses: https://cygwin.com/pipermail/cygwin/2022-March/250979.html
---
 winsup/cygwin/path.cc | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 4ad4e0821..dd8f6c043 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -3527,7 +3527,7 @@ restart:
 		      int remlen = QueryDosDeviceW (drive, remote, MAX_PATH);
 		      if (remlen < 3)
 			goto file_not_symlink; /* fallback */
-		      remlen -= 2;
+		      remlen -= 2; /* Two L'\0' */
 
 		      if (remote[remlen - 1] == L'\\')
 			remlen--;
@@ -3535,20 +3535,27 @@ restart:
 		      UNICODE_STRING rpath;
 		      RtlInitCountedUnicodeString (&rpath, remote,
 						   remlen * sizeof (WCHAR));
+		      const int uncp_len =
+			ro_u_uncp.Length / sizeof (WCHAR) - 1;
 		      if (RtlEqualUnicodePathPrefix (&rpath, &ro_u_uncp, TRUE))
-			remlen -= 6;
+			{
+			  remlen -= uncp_len;
+			  p = remote + uncp_len;
+			}
 		      else if ((p = wcschr (remote, L';'))
 			       && p + 3 < remote + remlen
 			       && wcsncmp (p + 1, drive, 2) == 0
 			       && (p = wcschr (p + 3, L'\\')))
-			remlen -= p - remote - 1;
+			remlen -= p - remote;
 		      else
 			goto file_not_symlink; /* fallback */
+		      if (wcsncasecmp (fpath.Buffer + uncp_len, p, remlen))
+			goto file_not_symlink; /* fallback (not expected) */
 		      /* Hackfest */
 		      fpath.Buffer[4] = drive[0]; /* Drive letter */
 		      fpath.Buffer[5] = L':';
-		      WCHAR *to = fpath.Buffer + 6;
-		      WCHAR *from = to + remlen;
+		      WCHAR *to = fpath.Buffer + 6; /* Next to L':' */
+		      WCHAR *from = fpath.Buffer + uncp_len + remlen;
 		      memmove (to, from,
 			       (wcslen (from) + 1) * sizeof (WCHAR));
 		      fpath.Length -= (from - to) * sizeof (WCHAR);
-- 
2.35.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] Cygwin: path: Add fallback for DFS mounted drive.
  2022-03-14 10:57 [PATCH v2] Cygwin: path: Add fallback for DFS mounted drive Takashi Yano
@ 2022-03-14 11:04 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2022-03-14 11:04 UTC (permalink / raw)
  To: cygwin-patches

Hi Takashi,

On Mar 14 19:57, Takashi Yano wrote:
> - If UNC path for DFS is mounted to a drive with drive letter, the
>   error "Too many levels of symbolic links" occurs when accessing
>   to that drive. This is because GetDosDeviceW() returns unexpected
>   string such as "\Device\Mup\DfsClient\;Z:000000000003fb89\dfsserver
>   \dfs\linkname" for the mounted UNC path "\??\UNC\fileserver\share".
>   This patch adds a workaround for this issue.
> 
>   Addresses: https://cygwin.com/pipermail/cygwin/2022-March/250979.html
> ---
>  winsup/cygwin/path.cc | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
> index 4ad4e0821..dd8f6c043 100644
> --- a/winsup/cygwin/path.cc
> +++ b/winsup/cygwin/path.cc
> @@ -3527,7 +3527,7 @@ restart:
>  		      int remlen = QueryDosDeviceW (drive, remote, MAX_PATH);
>  		      if (remlen < 3)
>  			goto file_not_symlink; /* fallback */
> -		      remlen -= 2;
> +		      remlen -= 2; /* Two L'\0' */
>  
>  		      if (remote[remlen - 1] == L'\\')
>  			remlen--;
> @@ -3535,20 +3535,27 @@ restart:
>  		      UNICODE_STRING rpath;
>  		      RtlInitCountedUnicodeString (&rpath, remote,
>  						   remlen * sizeof (WCHAR));
> +		      const int uncp_len =

I'd still prefer an unsigned type as USHORT or size_t here.  USHORT
because that's the type of the UNICODE_STRING::Length member, or
size_t because that's the standard type used for string lengths.

With that, GTG.

I just notice that remlen is int, too.  Given it represents the return
value from QueryDosDeviceW, it should ideally be converted to DWORD.


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-14 11:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-14 10:57 [PATCH v2] Cygwin: path: Add fallback for DFS mounted drive Takashi Yano
2022-03-14 11:04 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).