From 26c90215d543b80eccf6a259adf2ddd6e3143091 Mon Sep 17 00:00:00 2001 From: Jonathan Tron Date: Sat, 6 Jan 2024 13:35:48 +0100 Subject: [PATCH] Ensure we're reading up-to CRLF (`\r\n`) for commands 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`. --- features/support/test_client.rb | 2 +- lib/ftpd/command_loop.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/features/support/test_client.rb b/features/support/test_client.rb index 0a48f7b..68c047b 100644 --- a/features/support/test_client.rb +++ b/features/support/test_client.rb @@ -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 diff --git a/lib/ftpd/command_loop.rb b/lib/ftpd/command_loop.rb index 4ea66c5..1ae9178 100644 --- a/lib/ftpd/command_loop.rb +++ b/lib/ftpd/command_loop.rb @@ -8,6 +8,8 @@ class CommandLoop include Error + CRLF = "\r\n" + def initialize(session) @session = session end @@ -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