This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


The following commit(s) were added to refs/heads/master by this push:
     new 97f8ce64 FTP.getReply(boolean) incorrectly throws a 
MalformedServerReplyException if there is no reply message
97f8ce64 is described below

commit 97f8ce64aa04baf5375a5fc1bb0ee95188ee5d70
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Sun Feb 16 12:47:13 2025 -0500

    FTP.getReply(boolean) incorrectly throws a MalformedServerReplyException
    if there is no reply message
    
    error-response = error-code SP *TCHAR CRLF
    error-code     = ("4" / "5") 2DIGIT
---
 src/main/java/org/apache/commons/net/ftp/FTP.java | 26 ++++++++++++++++-------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/ftp/FTP.java 
b/src/main/java/org/apache/commons/net/ftp/FTP.java
index d6a3ec70..ffb972b3 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTP.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTP.java
@@ -599,6 +599,21 @@ public class FTP extends SocketClient {
         return getReply(true);
     }
 
+    /**
+     * Reads the reply line.
+     * <p>
+     * Syntax:
+     * </p>
+     *
+     * <pre>{@code
+     * error-response = error-code SP *TCHAR CRLF
+     * error-code     = ("4" / "5") 2DIGIT
+     * }</pre>
+     *
+     * @param reportReply whether to fire a reply received event.
+     * @return the reply code.
+     * @throws IOException If an I/O error occurs.
+     */
     private int getReply(final boolean reportReply) throws IOException {
         final int length;
         _newReplyString = true;
@@ -636,13 +651,8 @@ public class FTP extends SocketClient {
                     // returning too soon after encountering a naked CR or 
some other
                     // anomaly.
                 } while (isStrictMultilineParsing() ? strictCheck(line, code) 
: lenientCheck(line));
-            } else if (isStrictReplyParsing()) {
-                if (length == REPLY_CODE_LEN + 1) { // expecting some text
-                    throw new MalformedServerReplyException("Truncated server 
reply: '" + line + "'");
-                }
-                if (sep != SP) {
-                    throw new MalformedServerReplyException("Invalid server 
reply: '" + line + "'");
-                }
+            } else if (isStrictReplyParsing() && sep != SP) {
+                throw new MalformedServerReplyException("Invalid server reply: 
'" + line + "'");
             }
         } else if (isStrictReplyParsing()) {
             throw new MalformedServerReplyException("Truncated server reply: 
'" + line + "'");
@@ -987,7 +997,7 @@ public class FTP extends SocketClient {
      *                                      independently as itself.
      * @throws IOException                  If an I/O error occurs while 
either sending the command or receiving the server reply.
      */
-    public int opts(final String commandName, String commandOptions) throws 
IOException {
+    public int opts(final String commandName, final String commandOptions) 
throws IOException {
         return sendCommand(FTPCmd.OPTS, commandName + SP + commandOptions);
     }
 

Reply via email to