From 3aec0f00b186a669606767401892b9e9f8b1b84a Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 10 Nov 2009 08:54:24 +0000 Subject: [PATCH] * fhandler_disk_file.cc (is_volume_mountpoint): Align check with symlink_info::check_reparse_point(). * path.cc (symlink_info::check_reparse_point): Rearrange slightly. Add code path for unrecognized repare point types. Add comment. --- winsup/cygwin/ChangeLog | 7 +++++++ winsup/cygwin/fhandler_disk_file.cc | 7 ++++++- winsup/cygwin/path.cc | 32 ++++++++++++++++------------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 4a68aba60..96597cfd1 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2009-11-10 Corinna Vinschen + + * fhandler_disk_file.cc (is_volume_mountpoint): Align check with + symlink_info::check_reparse_point(). + * path.cc (symlink_info::check_reparse_point): Rearrange slightly. + Add code path for unrecognized repare point types. Add comment. + 2009-11-09 Corinna Vinschen * path.cc (symlink_info::check_reparse_point): Always check diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index e57000472..15e473989 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -154,6 +154,7 @@ is_volume_mountpoint (POBJECT_ATTRIBUTES attr) bool ret = false; IO_STATUS_BLOCK io; HANDLE reph; + UNICODE_STRING subst; if (NT_SUCCESS (NtOpenFile (&reph, READ_CONTROL, attr, &io, FILE_SHARE_VALID_FLAGS, @@ -166,7 +167,11 @@ is_volume_mountpoint (POBJECT_ATTRIBUTES attr) &io, FSCTL_GET_REPARSE_POINT, NULL, 0, (LPVOID) rp, MAXIMUM_REPARSE_DATA_BUFFER_SIZE)) && rp->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT - && rp->SymbolicLinkReparseBuffer.PrintNameLength == 0) + && (RtlInitCountedUnicodeString (&subst, + (WCHAR *)((char *)rp->MountPointReparseBuffer.PathBuffer + + rp->MountPointReparseBuffer.SubstituteNameOffset), + rp->MountPointReparseBuffer.SubstituteNameLength), + RtlEqualUnicodePathPrefix (&subst, &ro_u_volume, TRUE))) ret = true; NtClose (reph); } diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index daf780e84..6238f2bce 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -1844,6 +1844,7 @@ symlink_info::check_reparse_point (HANDLE h) NTSTATUS status; IO_STATUS_BLOCK io; PREPARSE_DATA_BUFFER rp = (PREPARSE_DATA_BUFFER) tp.c_get (); + UNICODE_STRING subst; char srcbuf[SYMLINK_MAX + 7]; status = NtFsControlFile (h, NULL, NULL, NULL, &io, FSCTL_GET_REPARSE_POINT, @@ -1857,18 +1858,12 @@ symlink_info::check_reparse_point (HANDLE h) return 0; } if (rp->ReparseTag == IO_REPARSE_TAG_SYMLINK) - { - sys_wcstombs (srcbuf, SYMLINK_MAX + 1, - (WCHAR *)((char *)rp->SymbolicLinkReparseBuffer.PathBuffer - + rp->SymbolicLinkReparseBuffer.SubstituteNameOffset), - rp->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof (WCHAR)); - pflags = PATH_SYMLINK | PATH_REP; - fileattr &= ~FILE_ATTRIBUTE_DIRECTORY; - } + RtlInitCountedUnicodeString (&subst, + (WCHAR *)((char *)rp->SymbolicLinkReparseBuffer.PathBuffer + + rp->SymbolicLinkReparseBuffer.SubstituteNameOffset), + rp->SymbolicLinkReparseBuffer.SubstituteNameLength); else if (rp->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT) { - UNICODE_STRING subst; - RtlInitCountedUnicodeString (&subst, (WCHAR *)((char *)rp->MountPointReparseBuffer.PathBuffer + rp->MountPointReparseBuffer.SubstituteNameOffset), @@ -1880,11 +1875,20 @@ symlink_info::check_reparse_point (HANDLE h) volume mount point. */ return -1; } - sys_wcstombs (srcbuf, SYMLINK_MAX + 1, subst.Buffer, - subst.Length / sizeof (WCHAR)); - pflags = PATH_SYMLINK | PATH_REP; - fileattr &= ~FILE_ATTRIBUTE_DIRECTORY; } + else + { + /* Maybe it's a reparse point, but it's certainly not one we + recognize. Drop the REPARSE file attribute so we don't even + try to use the flag for some special handling. It's just some + arbitrary file or directory for us. */ + fileattr &= ~FILE_ATTRIBUTE_REPARSE_POINT; + return 0; + } + sys_wcstombs (srcbuf, SYMLINK_MAX + 7, subst.Buffer, + subst.Length / sizeof (WCHAR)); + pflags = PATH_SYMLINK | PATH_REP; + fileattr &= ~FILE_ATTRIBUTE_DIRECTORY; return posixify (srcbuf); }