Skip to content
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

Fix FTP crash on certain servers #433

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/FtpFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,7 @@ void TFTPFileSystem::ReadCurrentDirectory()
// and immediately after call to CWD,
// later our current directory may be not synchronized with FZAPI current
// directory anyway, see comments in EnsureLocation
if (FReadCurrentDirectory || DebugAlwaysFalse(FCurrentDirectory.IsEmpty()))
if (FReadCurrentDirectory || FCurrentDirectory.IsEmpty())
{
const UnicodeString Command = "PWD";
SendCommand(Command);
Expand Down
8 changes: 4 additions & 4 deletions src/filezilla/AsyncProxySocketLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void CAsyncProxySocketLayer::OnReceive(int nErrorCode)
int32_t sz = nb::safe_strlen(tmp) + nb::safe_strlen(buffer);
m_pStrBuffer = nb::chcalloc(sz + 1);
strncpy_s(m_pStrBuffer, sz + 1, tmp, nb::safe_strlen(tmp));
strncpy_s(m_pStrBuffer + nb::safe_strlen(tmp), sz - nb::safe_strlen(buffer), buffer, nb::safe_strlen(buffer));
strncpy_s(m_pStrBuffer + nb::safe_strlen(tmp), sz - nb::safe_strlen(tmp) + 1, buffer, nb::safe_strlen(buffer));
nb_free(tmp);
}
memset(buffer, 0, 9);
Expand Down Expand Up @@ -510,7 +510,7 @@ void CAsyncProxySocketLayer::OnReceive(int nErrorCode)
{
char *tmp = nb::chcalloc(pos-m_pStrBuffer + 1);
tmp[pos-m_pStrBuffer] = 0;
strncpy_s(tmp, pos-m_pStrBuffer, m_pStrBuffer, nb::safe_strlen(m_pStrBuffer));
strncpy_s(tmp, pos-m_pStrBuffer + 1, m_pStrBuffer, nb::safe_strlen(m_pStrBuffer));
ConnectionFailed(WSAECONNABORTED, tmp);
return;
}
Expand Down Expand Up @@ -615,7 +615,7 @@ BOOL CAsyncProxySocketLayer::Connect( LPCTSTR lpszHostAddress, UINT nHostPort )
{
nb_free(m_pProxyPeerHost);
m_pProxyPeerHost = nb::chcalloc(nb::safe_strlen(T2CA(lpszHostAddress))+1);
strncpy_s(m_pProxyPeerHost, nb::safe_strlen(T2CA(lpszHostAddress)), T2CA(lpszHostAddress), nb::safe_strlen(lpszHostAddress));
strncpy_s(m_pProxyPeerHost, nb::safe_strlen(T2CA(lpszHostAddress))+1, T2CA(lpszHostAddress), nb::safe_strlen(lpszHostAddress));
}
return res;

Expand Down Expand Up @@ -708,7 +708,7 @@ void CAsyncProxySocketLayer::OnConnect(int nErrorCode)
command[6]=0;
command[7]=1;
//Add host as URL
strncpy_s(&command[9], nb::safe_strlen(lpszAscii), lpszAscii, nb::safe_strlen(lpszAscii));
strncpy_s(&command[9], nb::safe_strlen(lpszAscii)+1, lpszAscii, nb::safe_strlen(lpszAscii));
len+=(int)nb::safe_strlen(lpszAscii)+1;
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/filezilla/FtpListResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ bool CFtpListResult::ParseShortDate(const char *str, int len, t_directory::t_dir
if (!numeric)
{
char *tmpstr = nb::chcalloc(i + 1);
strncpy_s(tmpstr, i, str, i);
strncpy_s(tmpstr, i + 1, str, i);
tmpstr[i] = 0;
strlwr(tmpstr);

Expand Down Expand Up @@ -1334,7 +1334,7 @@ BOOL CFtpListResult::parseAsUnix(const char *line, const int linelen, t_director
//Maybe the server has left no space between the group and the size
//because of stupid alignment
char *tmpstr = nb::chcalloc(tokenlen + 1);
strncpy_s(tmpstr, tokenlen, str, tokenlen);
strncpy_s(tmpstr, tokenlen + 1, str, tokenlen);
tmpstr[tokenlen] = 0;
strlwr(tmpstr);

Expand Down