[PATCH] fix unlink for Cygwin 1.5.25-15 -- unintended data loss with symbolic file links

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] fix unlink for Cygwin 1.5.25-15 -- unintended data loss with symbolic file links

Jason-245
Please consider the patch below for inclusion in the Cygwin 1.5 branch which
corrects the deletion of symbolic link file types (Vista file reparse
points).

The problem is that CreateFile will open the target and not the link.  See
the MSDN page
http://msdn.microsoft.com/en-us/library/aa365682(VS.85).aspx#CreateFile for
a more detailed description of Vista's symbolic link handling.
 
Thanks,
  Jason

---

2008-09-15  Jason Gouger <cygwin at jason-gouger.com>

        * syscalls.cc: Fix 'unlink' so that it will delete the symbolic link
        and not the target file for Vista's file reparse points.

Index: cygwin/syscalls.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/syscalls.cc,v
retrieving revision 1.403.4.3
diff -b -u -p -r1.403.4.3 syscalls.cc
--- cygwin/syscalls.cc 12 Nov 2007 15:30:20 -0000 1.403.4.3
+++ cygwin/syscalls.cc 15 Sep 2008 21:06:10 -0000
@@ -207,7 +207,7 @@ unlink (const char *ourname)
     {
       HANDLE h;
       h = CreateFile (win32_name, 0, FILE_SHARE_READ, &sec_none_nih,
-      OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, 0);
+      OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT |
FILE_FLAG_DELETE_ON_CLOSE, 0);
       if (h != INVALID_HANDLE_VALUE)
  {
   if (wincap.has_hard_links () && setattrs)

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] fix unlink for Cygwin 1.5.25-15 -- unintended data loss with symbolic file links

Christopher Faylor-8
On Mon, Sep 15, 2008 at 02:31:07PM -0700, Jason wrote:
>Please consider the patch below for inclusion in the Cygwin 1.5 branch which
>corrects the deletion of symbolic link file types (Vista file reparse
>points).
>
>The problem is that CreateFile will open the target and not the link.  See
>the MSDN page
>http://msdn.microsoft.com/en-us/library/aa365682(VS.85).aspx#CreateFile for
>a more detailed description of Vista's symbolic link handling.

Sorry but we're not anticipating any new releases of Cygwin 1.5.x.

cgf
Reply | Threaded
Open this post in threaded view
|

RE: [PATCH] fix unlink for Cygwin 1.5.25-15 -- unintended data loss with symbolic file links

Jason-245
On Monday, September 15, 2008 3:29 PM, Christopher Faylor wrote:
> On Mon, Sep 15, 2008 at 02:31:07PM -0700, Jason wrote:
> >Please consider the patch below for inclusion in the Cygwin 1.5 branch
which
> >corrects the deletion of symbolic link file types (Vista file reparse
> >points).
> >
> >The problem is that CreateFile will open the target and not the link.
See
> >the MSDN page
> >http://msdn.microsoft.com/en-us/library/aa365682(VS.85).aspx#CreateFile
for
> >a more detailed description of Vista's symbolic link handling.
>
> Sorry but we're not anticipating any new releases of Cygwin 1.5.x.
>
> cgf

Okay, I thought I'd submit the trivial patch just in case someone else runs
into the problem.  The bug has very interesting side effects if someone does
a "rm -rf" of a directory which may contain such symbolic links.  Luckily I
had a backup.  I look forward to the 1.7 release!