Skip to content

Commit d973094

Browse files
committed
Merge pull request #101 from dscho/fix-dotdot-native_symlink-gfw
Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 086201e + 4ee8a03 commit d973094

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

winsup/cygwin/fhandler/socket_inet.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
#undef u_long
2121
#define u_long __ms_u_long
2222
#include <w32api/ws2tcpip.h>
23+
/* 2025-06-09: win32api headers v13 now define a cmsghdr type which clashes with
24+
our socket.h. Arrange not to see it here. */
25+
#undef cmsghdr
26+
#define cmsghdr __ms_cmsghdr
2327
#include <w32api/mswsock.h>
28+
#undef cmsghdr
2429
#include <w32api/mstcpip.h>
2530
#include <netinet/tcp.h>
2631
#include <netinet/udp.h>

winsup/cygwin/fhandler/socket_local.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
#define u_long __ms_u_long
2222
#include "ntsecapi.h"
2323
#include <w32api/ws2tcpip.h>
24+
/* 2025-06-09: win32api headers v13 now define a cmsghdr type which clashes with
25+
our socket.h. Arrange not to see it here. */
26+
#undef cmsghdr
27+
#define cmsghdr __ms_cmsghdr
2428
#include <w32api/mswsock.h>
29+
#undef cmsghdr
2530
#include <unistd.h>
2631
#include <asm/byteorder.h>
2732
#include <sys/socket.h>

winsup/cygwin/local_includes/ntdll.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ typedef struct _FILE_DISPOSITION_INFORMATION_EX // 64
489489
ULONG Flags;
490490
} FILE_DISPOSITION_INFORMATION_EX, *PFILE_DISPOSITION_INFORMATION_EX;
491491

492+
#if __MINGW64_VERSION_MAJOR < 13
493+
492494
typedef struct _FILE_STAT_INFORMATION // 68
493495
{
494496
LARGE_INTEGER FileId;
@@ -509,6 +511,8 @@ typedef struct _FILE_CASE_SENSITIVE_INFORMATION // 71
509511
ULONG Flags;
510512
} FILE_CASE_SENSITIVE_INFORMATION, *PFILE_CASE_SENSITIVE_INFORMATION;
511513

514+
#endif
515+
512516
enum {
513517
FILE_LINK_REPLACE_IF_EXISTS = 0x01,
514518
FILE_LINK_POSIX_SEMANTICS = 0x02,

winsup/cygwin/net.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ details. */
1818
#undef u_long
1919
#define u_long __ms_u_long
2020
#include <w32api/ws2tcpip.h>
21+
/* 2025-06-09: win32api headers v13 now define a cmsghdr type which clashes with
22+
our socket.h. Arrange not to see it here. */
23+
#undef cmsghdr
24+
#define cmsghdr __ms_cmsghdr
2125
#include <w32api/mswsock.h>
26+
#undef cmsghdr
2227
#include <w32api/iphlpapi.h>
2328
#define gethostname cygwin_gethostname
2429
#include <unistd.h>

winsup/cygwin/path.cc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,9 +2031,18 @@ symlink_native (const char *oldpath, path_conv &win32_newpath)
20312031
while (towupper (*++c_old) == towupper (*++c_new))
20322032
;
20332033
/* The last component could share a common prefix, so make sure we end
2034-
up on the first char after the last common backslash. */
2035-
while (c_old[-1] != L'\\')
2036-
--c_old, --c_new;
2034+
up on the first char after the last common backslash.
2035+
2036+
However, if c_old is a strict prefix of c_new (at a component
2037+
boundary), or vice versa, then do not try to find the last common
2038+
backslash. */
2039+
if ((!*c_old || *c_old == L'\\') && (!*c_new || *c_new == L'\\'))
2040+
c_old += !!*c_old, c_new += !!*c_new;
2041+
else
2042+
{
2043+
while (c_old[-1] != L'\\')
2044+
--c_old, --c_new;
2045+
}
20372046

20382047
/* 2. Check if prefix is long enough. The prefix must at least points to
20392048
a complete device: \\?\X:\ or \\?\UNC\server\share\ are the minimum
@@ -2058,8 +2067,10 @@ symlink_native (const char *oldpath, path_conv &win32_newpath)
20582067
final_oldpath = &final_oldpath_buf;
20592068
final_oldpath->Buffer = tp.w_get ();
20602069
PWCHAR e_old = final_oldpath->Buffer;
2061-
while (num-- > 0)
2062-
e_old = wcpcpy (e_old, L"..\\");
2070+
while (num > 1 || (num == 1 && *c_old))
2071+
e_old = wcpcpy (e_old, L"..\\"), num--;
2072+
if (num > 0)
2073+
e_old = wcpcpy (e_old, L"..");
20632074
wcpcpy (e_old, c_old);
20642075
}
20652076
}

0 commit comments

Comments
 (0)