Skip to content

Commit

Permalink
Fix FTP/550 (ENODEV) for clients using "LIST -a"
Browse files Browse the repository at this point in the history
The test for additional switches to the LIST command
must be performed before the path is joined. Otherwise,
the path will never be empty and the test will be skipped.
Fixes ENODEV error (FTP/550) on clients using "LIST -a".
  • Loading branch information
eku authored and Maschell committed Nov 23, 2024
1 parent f03f310 commit b4e6db7
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions source/ftpSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1438,15 +1438,27 @@ void FtpSession::xferDir (char const *const args_, XferDirMode const mode_, bool
(args_[2] == '\0' || args_[2] == ' ');

// an argument was provided
auto const path = buildResolvedPath (m_cwd, args_);
if (path.empty ())

// work around broken clients that think LIST -a/-l is valid
if (workaround_)
{
if (needWorkaround)
if (args_[0] == '-' && (args_[1] == 'a' || args_[1] == 'l'))
{
xferDir (args_ + 2 + (args_[2] == ' '), mode_, false);
return;
char const *args = &args_[2];
if (*args == '\0' || *args == ' ')
{
if (*args == ' ')
++args;

xferDir (args, mode_, false);
return;
}
}
}

auto const path = buildResolvedPath (m_cwd, args_);
if (path.empty ())
{
sendResponse ("550 %s\r\n", std::strerror (errno));
setState (State::COMMAND, true, true);
return;
Expand All @@ -1455,12 +1467,6 @@ void FtpSession::xferDir (char const *const args_, XferDirMode const mode_, bool
stat_t st;
if (tzStat (path.c_str (), &st) != 0)
{
if (needWorkaround)
{
xferDir (args_ + 2 + (args_[2] == ' '), mode_, false);
return;
}

sendResponse ("550 %s\r\n", std::strerror (errno));
setState (State::COMMAND, true, true);
return;
Expand Down

0 comments on commit b4e6db7

Please sign in to comment.