ned14/llfio

`current_working_directory` may read out of bounds and uninitialized memory with long paths

BurningEnlightenment opened this issue · 3 comments

wchar_t buffer[MAX_PATH];
DWORD written = GetCurrentDirectoryW(sizeof(buffer) / sizeof(wchar_t), buffer);
if(0 == written)
{
return win32_error();
}
return path_handle::path(path_view(buffer, written, path_view::zero_terminated));

GetCurrentDirectory returns the required buffer size if the path doesn't fit into the given buffer (see Windows docs). In case of a long path aware application this can lead to passing the uninitialized buffer with an out of bounds size to the fs_handle constructor.

@ned14 given that we generally don't allocate heap memory, we would either need to increase the buffer size to 2^15 or check written > MAX_PATH and return an error code, right?

ned14 commented

Sorry, forgot about this one with the Varna meeting. And I'm heading to New York tomorrow for a few days for the new job.

Stack is cheap on Windows, so I'd just bump that buffer to 32769 like most other parts of LLFIO.