Skip to content

Commit c1fd75d

Browse files
committed
CoreFoundation: ensure that the bundle path exists
On Windows, we would assume that the bundle path computed will exist. However, it is possible to have an executable using Foundation without a bundle. In such a case, the main bundle would never be setup, and when SwiftFoundation would attempt to access it, it would assume that it was setup. This would cause a failure due to the forced unwrapping.
1 parent 1f6972f commit c1fd75d

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

CoreFoundation/PlugIn.subproj/CFBundle_Executable.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ static CFURLRef _CFBundleCopyBundleURLForExecutablePath(CFStringRef str) {
344344
buffLen += extensionLength;
345345
outstr = CFStringCreateWithCharactersNoCopy(kCFAllocatorSystemDefault, buff, buffLen, kCFAllocatorNull);
346346
url = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, outstr, PLATFORM_PATH_STYLE, true);
347+
if (!_CFURLExists(url)) {
348+
CFRelease(url);
349+
url = NULL;
350+
}
347351
CFRelease(outstr);
348352
}
349353
}

0 commit comments

Comments
 (0)