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
commit 71918811e914c7a78ce9c2b6bc5bd64781115c02 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Feb 24 13:46:08 2024 -0500 Internal refactoring Validate mode input --- src/main/java/org/apache/commons/net/ftp/FTP.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 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 ae4c72c4..862cbbd4 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTP.java +++ b/src/main/java/org/apache/commons/net/ftp/FTP.java @@ -426,6 +426,13 @@ public class FTP extends SocketClient { return sendCommand(FTPCmd.CDUP); } + private int checkMode(final int index) { + if (index >= MODES.length()) { + throw new IllegalArgumentException("Unknown mode"); + } + return index; + } + /** * A convenience method to send the FTP CWD command to the server, receive the reply, and return the reply code. * @@ -907,12 +914,13 @@ public class FTP extends SocketClient { return sendCommand(FTPCmd.MODE, modeStringAt(mode)); } - private char modeCharAt(final int fileType) { - return MODES.charAt(fileType); + private char modeCharAt(final int index) { + return MODES.charAt(checkMode(index)); } - private String modeStringAt(final int mode) { - return MODES.substring(mode, mode + 1); + private String modeStringAt(final int index) { + checkMode(index); + return MODES.substring(index, index + 1); } /**