Skip to content

Switch to a safer technique for obtaining the working directory on Windows #1277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jakepetroules
Copy link
Contributor

Instead of looping 8 times to work around the TOCTOU issue with sizing the current directory buffer, instead keep doubling the buffer up until the 32767 character limit until the result fits. This ensures we always get a working directory if GetWorkingDirectoryW didn't return some other error, rather than returning nil in the case of a race condition.

@jakepetroules
Copy link
Contributor Author

@swift-ci test

@jakepetroules jakepetroules force-pushed the safe-getworkingdirectory branch from 17a7fd5 to dfcef2f Compare May 1, 2025 17:19
@jakepetroules
Copy link
Contributor Author

@swift-ci test

@jakepetroules jakepetroules added the windows Issue regarding compiling/running on Windows label May 1, 2025
…ndows

Instead of looping 8 times to work around the TOCTOU issue with sizing the current directory buffer, instead keep doubling the buffer up until the 32767 character limit until the result fits. This ensures we always get a working directory if GetWorkingDirectoryW didn't return some other error, rather than returning nil in the case of a race condition.
@jakepetroules jakepetroules force-pushed the safe-getworkingdirectory branch from dfcef2f to f77a636 Compare May 2, 2025 18:30
@jakepetroules
Copy link
Contributor Author

@swift-ci test

@jakepetroules jakepetroules merged commit 435a2bb into swiftlang:main May 3, 2025
15 checks passed
@jakepetroules jakepetroules deleted the safe-getworkingdirectory branch May 3, 2025 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
windows Issue regarding compiling/running on Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants