You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Switch to a safer technique for obtaining the working directory on Windows
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.
/// Calls a Win32 API function that fills a (potentially long path) null-terminated string buffer by continually attempting to allocate more memory up until the true max path is reached.
296
+
/// This is especially useful for protecting against race conditions like with GetCurrentDirectoryW where the measured length may no longer be valid on subsequent calls.
297
+
/// - parameter initialSize: Initial size of the buffer (including the null terminator) to allocate to hold the returned string.
298
+
/// - parameter maxSize: Maximum size of the buffer (including the null terminator) to allocate to hold the returned string.
299
+
/// - parameter body: Closure to call the Win32 API function to populate the provided buffer.
300
+
/// Should return the number of UTF-16 code units (not including the null terminator) copied, 0 to indicate an error.
301
+
/// If the buffer is not of sufficient size, should return a value greater than or equal to the size of the buffer.
0 commit comments