Skip to content

Commit

Permalink
Fixed potential crash on Windows (#62)
Browse files Browse the repository at this point in the history
Fixed potential crash on Windows by passing a pointer to a DWORD instead of nullpointer.
According to the documentation, that parameter can only be NULL for OVERLAPPED io, which is not what we are doing here.
  • Loading branch information
FlorianReimold authored Nov 7, 2023
1 parent c34e3eb commit bf064c7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fineftp-server/src/win32/file_man.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ WriteableFile::WriteableFile(const std::string& filename, std::ios::openmode mod
dwCreationDisposition = CREATE_ALWAYS; // Not Append => Create new file
}

// https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew
#if !defined(__GNUG__)
auto wfilename = StrConvert::Utf8ToWide(filename);
handle_ = ::CreateFileW(wfilename.c_str(), dwDesiredAccess, FILE_SHARE_DELETE, nullptr, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, nullptr);
Expand Down Expand Up @@ -161,7 +162,8 @@ void WriteableFile::close()

void WriteableFile::write(const char* data, std::size_t sz)
{
(void)::WriteFile(handle_, data, static_cast<DWORD>(sz), nullptr, nullptr);
DWORD bytes_written{}; // Unused, but required according to https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-writefile
(void)::WriteFile(handle_, data, static_cast<DWORD>(sz), &bytes_written, nullptr);
}

}
Expand Down

0 comments on commit bf064c7

Please sign in to comment.