Skip to content

Commit

Permalink
Fixed Win32 writable file, added more tests and removed Path Vulnerab…
Browse files Browse the repository at this point in the history
…ility Test for now
  • Loading branch information
FlorianReimold committed Oct 24, 2023
1 parent 87bce95 commit 02fd0de
Show file tree
Hide file tree
Showing 3 changed files with 343 additions and 10 deletions.
10 changes: 6 additions & 4 deletions fineftp-server/src/ftp_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace fineftp
}
else
{
std::cerr << "Command write error: " << ec.message() << std::endl;
std::cerr << "Command write error for message " << me->command_output_queue_.front() << ec.message() << std::endl;
}
}
));
Expand Down Expand Up @@ -254,10 +254,12 @@ namespace fineftp
// Close command socket
command_strand_.post([me = shared_from_this()]()
{
// TODO: Decide when to close the command socket. Doing that here actually breaks sending the "221 Closing command socket" message.

// Properly close command socket
asio::error_code ec;
me->command_socket_.shutdown(asio::ip::tcp::socket::shutdown_both, ec);
me->command_socket_.close(ec);
//asio::error_code ec;
//me->command_socket_.shutdown(asio::ip::tcp::socket::shutdown_both, ec);
//me->command_socket_.close(ec);
});
}
else
Expand Down
5 changes: 3 additions & 2 deletions fineftp-server/src/win32/file_man.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ WriteableFile::WriteableFile(const std::string& filename, std::ios::openmode mod
(void)mode;
#if !defined(__GNUG__)
auto wfilename = StrConvert::Utf8ToWide(filename);
handle_ = ::CreateFileW(wfilename.c_str(), GENERIC_WRITE, FILE_SHARE_DELETE, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
handle_ = ::CreateFileW(wfilename.c_str(), GENERIC_WRITE, FILE_SHARE_DELETE, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL /*FILE_FLAG_WRITE_THROUGH*/, 0);
#else
handle_ = ::CreateFileA(filename.c_str(), GENERIC_WRITE, FILE_SHARE_DELETE, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
handle_ = ::CreateFileA(filename.c_str(), GENERIC_WRITE, FILE_SHARE_DELETE, nullptr, CREATE_NEW, /*FILE_ATTRIBUTE_NORMAL*/ FILE_FLAG_WRITE_THROUGH, 0);
#endif

if (INVALID_HANDLE_VALUE != handle_ && (mode & std::ios::app) == std::ios::app)
Expand All @@ -139,6 +139,7 @@ void WriteableFile::close()
if (INVALID_HANDLE_VALUE != handle_)
{
::CloseHandle(handle_);
handle_ = INVALID_HANDLE_VALUE;
}
}

Expand Down
Loading

0 comments on commit 02fd0de

Please sign in to comment.