Skip to content

Commit

Permalink
Ensure we're reading up-to CRLF (\r\n) for commands
Browse files Browse the repository at this point in the history
In TLS, the socket is an `OpenSSL::SSLSocket`, calling `gets` will try
to read the buffer using the value of `$/` (`\n` on Linux/MacOS) as separator,
which seems to mess with the `BufferedIO`.
  • Loading branch information
JonathanTron committed Jan 6, 2024
1 parent 3858830 commit 26c9021
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion features/support/test_client.rb
Expand Up @@ -213,7 +213,7 @@ def with_binary(*args, &block)
if @override_with_binary
block.call
else
return orig_with_binary(*args, &block)
orig_with_binary(*args, &block)
end
end

Expand Down
4 changes: 3 additions & 1 deletion lib/ftpd/command_loop.rb
Expand Up @@ -8,6 +8,8 @@ class CommandLoop

include Error

CRLF = "\r\n"

def initialize(session)
@session = session
end
Expand Down Expand Up @@ -62,7 +64,7 @@ def gets_with_timeout(socket)
socket = socket.to_io if @session.tls_enabled? && !socket.encrypted?
ready = IO.select([socket], nil, nil, config.session_timeout)
timeout if ready.nil?
ready[0].first.gets
ready[0].first.gets(CRLF)
end

def timeout
Expand Down

0 comments on commit 26c9021

Please sign in to comment.