https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=60c67169d69577179bfe7b7f9d8c40fdb0a9b5f7

commit 60c67169d69577179bfe7b7f9d8c40fdb0a9b5f7
Author: Johannes Schindelin <[email protected]>
Date:   Mon Oct 6 16:08:17 2025 +0200

    Cygwin: symlink_native: allow linking to `.` again
    
    In 827743ab76 (Cygwin: symlink_native: allow linking to `..`,
    2025-06-20), I fixed linking to `..` (which had inadvertently
    targeted an incorrect location prior to that fix), but inadvertently
    broke linking to `.` (which would now try to pass the empty string as
    `lpTargetFileName` to `CreateSymbolicLinkW()`, failing with an
    `ERROR_INVALID_REPARSE_DATA` which would be surfaced as "Permission
    denied").
    
    Let's fix this by special-casing an empty string as path as referring to
    the current directory.
    
    Note: It is unclear to me why the `winsymlinks:nativestrict` code path
    even tries to simplify the symbolic link's target path (e.g. turn an
    absolute path into a relative one). As long as it refers to a regular
    Win32 file or directory, I would think that even something like
    `././c` should have only the slashes converted, not the path
    simplified (i.e. `.\.\c` instead of `c`). But that's a larger
    discussion, and I would like to have the bug worked around swiftly.
    
    Fixes: 827743ab76 (Cygwin: symlink_native: allow linking to `..`, 
2025-06-20)
    Signed-off-by: Johannes Schindelin <[email protected]>

Diff:
---
 winsup/cygwin/path.cc       | 5 ++++-
 winsup/cygwin/release/3.6.5 | 2 ++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 310876b5a..710775e38 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -1895,7 +1895,10 @@ symlink_native (const char *oldpath, path_conv 
&win32_newpath)
            e_old = wcpcpy (e_old, L"..\\"), num--;
          if (num > 0)
            e_old = wcpcpy (e_old, L"..");
-         wcpcpy (e_old, c_old);
+         if (e_old == final_oldpath->Buffer && c_old[0] == L'\0')
+           wcpcpy (e_old, L".");
+         else
+           wcpcpy (e_old, c_old);
        }
     }
   /* If the symlink target doesn't exist, don't create native symlink.
diff --git a/winsup/cygwin/release/3.6.5 b/winsup/cygwin/release/3.6.5
index d7cf8381f..8a4eff051 100644
--- a/winsup/cygwin/release/3.6.5
+++ b/winsup/cygwin/release/3.6.5
@@ -29,3 +29,5 @@ Fixes:
 - Fix multi-thread safety of fork()/exec() by adding the same locking as was
   done for spawn.
   Addresses: https://cygwin.com/pipermail/cygwin/2025-September/258801.html
+
+- Fix native symlink to '.' (a regresison in 3.6.4)

Reply via email to