Commons Net
  1. Commons Net
  2. NET-442

StringIndexOutOfBoundsException: String index out of range: -1 if server respond with root is current directory

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.1
    • Fix Version/s: 3.2
    • Component/s: FTP
    • Labels:
      None
    • Environment:

      Ubuntu linux 11.04

      Description

      I've an ftp server that at the pwd request responds with |257 root is current directory.| without any double quotes present and the lib gives up with this exception:

      java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      at java.lang.String.substring(String.java:1949)
      at org.apache.commons.net.ftp.FTPClient.__parsePathname(FTPClient.java:469)
      at org.apache.commons.net.ftp.FTPClient.printWorkingDirectory(FTPClient.java:2374)

      Probably it's only needed a check in __parsePathname

      private String __parsePathname(String reply)
      {
      int begin, end;

      begin = reply.indexOf('"') + 1;
      end = reply.indexOf('"', begin);

      if (begin == -1 && end == -1)

      { return reply; }

      return reply.substring(begin, end);
      }

        Activity

        Hide
        Sebb added a comment -

        URL: http://svn.apache.org/viewvc?rev=1296413&view=rev
        Log:
        NET-442 StringIndexOutOfBoundsException: String index out of range: -1 if server respond with
        root is current directory

        Modified:
        commons/proper/net/trunk/src/changes/changes.xml
        commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java

        Show
        Sebb added a comment - URL: http://svn.apache.org/viewvc?rev=1296413&view=rev Log: NET-442 StringIndexOutOfBoundsException: String index out of range: -1 if server respond with root is current directory Modified: commons/proper/net/trunk/src/changes/changes.xml commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPClient.java
        Hide
        Andrea Selva added a comment -

        The FTP server I use, is an embedded custom server, that has got many many problems to be defined FTP compliant. But I think that FTP client should gracefully say that a message is not well formatted instead of a bad IndexOutOfBounds, but I completely agree that the FTP server that raised up this behaviour is completely broken.

        The issue could be closed as not applicable.
        Andrea

        Show
        Andrea Selva added a comment - The FTP server I use, is an embedded custom server, that has got many many problems to be defined FTP compliant. But I think that FTP client should gracefully say that a message is not well formatted instead of a bad IndexOutOfBounds, but I completely agree that the FTP server that raised up this behaviour is completely broken. The issue could be closed as not applicable. Andrea
        Hide
        Sebb added a comment -

        That is not a valid response according to RFC959, however it might be worth adding the check.

        What is your server type?

        Also, if your FTP server supports directory names with spaces in them, how does it report PWD for them?

        Note: according to RFC959, embedded quotes need to be doubled-up; this is not done either.
        For example:
        MKD foo"bar
        257 "/usr/dm/foo""bar" directory created

        If we assume that the trailing comment never contains a double-quote, then the code can handle embedded quotes by looking for the last quote, and then de-duplicating the double-quotes.

        Show
        Sebb added a comment - That is not a valid response according to RFC959, however it might be worth adding the check. What is your server type? Also, if your FTP server supports directory names with spaces in them, how does it report PWD for them? Note: according to RFC959, embedded quotes need to be doubled-up; this is not done either. For example: MKD foo"bar 257 "/usr/dm/foo""bar" directory created If we assume that the trailing comment never contains a double-quote, then the code can handle embedded quotes by looking for the last quote, and then de-duplicating the double-quotes.

          People

          • Assignee:
            Unassigned
            Reporter:
            Andrea Selva
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development