Skip to content

Commit 47d3bab

Browse files
committed
Base.subproject: correct home directory handling on Windows
While we can enumerate the users using `NetUserEnum`, that does not guarantee that we get the full user information. Perform an explicit `NetUserGetInfo` to query the user information to get the home directory. Additionally, correct the `CFString` handling within the function where we were improperly using `CFStringCreateWithBytesNoCopy` which requires that the string is 8-bit encoded. We now use `CFStringCreateWithCharacters[NoCopy]` to properly create the `CFString` with unicode characters.
1 parent 0cfadd2 commit 47d3bab

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -594,17 +594,23 @@ CF_EXPORT CFURLRef CFCopyHomeDirectoryURLForUser(CFStringRef uName) {
594594
&dwToken);
595595
if (nStatus == NERR_Success || nStatus == ERROR_MORE_DATA) {
596596
for (unsigned uiEntry = 0; !home && uiEntry < dwEntriesRead; ++uiEntry) {
597+
USER_INFO_1 uiInfo;
598+
599+
if (NetUserGetInfo(NULL, pBuffer[uiEntry].usri1_name,
600+
1, &uiInfo) != NERR_Success)
601+
continue;
602+
597603
CFStringRef name =
598-
CFStringCreateWithCStringNoCopy(kCFAllocatorSystemDefault,
599-
pBuffer[uiEntry].usri1_name,
600-
kCFStringEncodingUTF16,
601-
kCFAllocatorNull);
604+
CFStringCreateWithCharactersNoCopy(kCFAllocatorSystemDefault,
605+
uiInfo.usri1_name,
606+
wcslen(uiInfo.usri1_name),
607+
kCFAllocatorNull);
602608

603-
if (CFEqual(uName, name)) {
609+
if (_CFStringEqual(uName, name)) {
604610
home = pBuffer[uiEntry].usri1_home_dir
605-
? CFStringCreateWithCString(kCFAllocatorSystemDefault,
606-
pBuffer[uiEntry].usri1_home_dir,
607-
kCFStringEncodingUTF16)
611+
? CFStringCreateWithCharacters(kCFAllocatorSystemDefault,
612+
uiInfo.usri1_home_dir,
613+
wcslen(uiInfo.usri1_home_dir))
608614
: CFSTR("");
609615
}
610616

0 commit comments

Comments
 (0)