From 4b8ffe746526df530c35a4b980b63d5f5cd1a2f4 Mon Sep 17 00:00:00 2001 From: Erik Kunze Date: Fri, 22 Nov 2024 15:38:29 +0100 Subject: [PATCH] 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". --- source/ftpSession.cpp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/source/ftpSession.cpp b/source/ftpSession.cpp index 82fb927..605e15c 100644 --- a/source/ftpSession.cpp +++ b/source/ftpSession.cpp @@ -1230,31 +1230,25 @@ void FtpSession::xferDir (char const *const args_, XferDirMode const mode_, bool if (std::strlen (args_) > 0) { // 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_) { - // work around broken clients that think LIST -a/-l is valid - if (workaround_) + if (args_[0] == '-' && (args_[1] == 'a' || args_[1] == 'l')) { - if (args_[0] == '-' && (args_[1] == 'a' || args_[1] == 'l')) + char const *args = &args_[2]; + if (*args == '\0' || *args == ' ') { - char const *args = &args_[2]; - if (*args == '\0' || *args == ' ') - { - if (*args == ' ') - ++args; + if (*args == ' ') + ++args; - xferDir (args, mode_, false); - return; - } + xferDir (args, mode_, false); + return; } } - - sendResponse ("550 %s\r\n", std::strerror (errno)); - setState (State::COMMAND, true, true); - return; } + auto const path = buildResolvedPath (m_cwd, args_); struct stat st; if (IOAbstraction::stat (path.c_str (), &st) != 0) {