Skip to content

Commit 5ee648b

Browse files
committed
Strip any UNC long path prefix from _wgetcwd
- This keeps any UNC long file or device prefix (\\?\ and \\.\) out of URL that were relative and then resolved to absolute urls.
1 parent 94ef6ab commit 5ee648b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sources/CoreFoundation/CFPlatform.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,9 +1140,18 @@ CF_EXPORT char *_NS_getcwd(char *dstbuf, size_t size) {
11401140
if (!buf) {
11411141
return NULL;
11421142
}
1143+
1144+
// Strip UNC-style prefixes (\\?\ and \\.\) from the wide character buffer
1145+
wchar_t *pathToConvert = buf;
1146+
size_t pathLen = wcslen(buf);
1147+
if (pathLen >= 4 && buf[0] == L'\\' && buf[1] == L'\\' && buf[3] == L'\\' &&
1148+
(buf[2] == L'?' || buf[2] == L'.')) {
1149+
// Skip the UNC prefix by advancing the pointer
1150+
pathToConvert = buf + 4;
1151+
}
11431152

11441153
// Convert result to UTF8
1145-
copyToNarrowFileSystemRepresentation(buf, (CFIndex)size, dstbuf);
1154+
copyToNarrowFileSystemRepresentation(pathToConvert, (CFIndex)size, dstbuf);
11461155
free(buf);
11471156
return dstbuf;
11481157
}

0 commit comments

Comments
 (0)