You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Andrea Selva (Created) (JIRA)" <ji...@apache.org> on 2012/02/15 09:09:59 UTC

[jira] [Created] (NET-442) StringIndexOutOfBoundsException: String index out of range: -1 if server respond with root is current directory

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

                 Key: NET-442
                 URL: https://issues.apache.org/jira/browse/NET-442
             Project: Commons Net
          Issue Type: Bug
          Components: FTP
    Affects Versions: 3.0.1
         Environment: Ubuntu linux 11.04
            Reporter: Andrea Selva


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);
    }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (NET-442) StringIndexOutOfBoundsException: String index out of range: -1 if server respond with root is current directory

Posted by "Sebb (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/NET-442?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebb resolved NET-442.
----------------------

       Resolution: Fixed
    Fix Version/s: 3.2
    
> StringIndexOutOfBoundsException: String index out of range: -1 if server respond with root is current directory
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: NET-442
>                 URL: https://issues.apache.org/jira/browse/NET-442
>             Project: Commons Net
>          Issue Type: Bug
>          Components: FTP
>    Affects Versions: 3.0.1
>         Environment: Ubuntu linux 11.04
>            Reporter: Andrea Selva
>             Fix For: 3.2
>
>
> 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);
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (NET-442) StringIndexOutOfBoundsException: String index out of range: -1 if server respond with root is current directory

Posted by "Andrea Selva (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/NET-442?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13220415#comment-13220415 ] 

Andrea Selva commented on NET-442:
----------------------------------

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
                
> StringIndexOutOfBoundsException: String index out of range: -1 if server respond with root is current directory
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: NET-442
>                 URL: https://issues.apache.org/jira/browse/NET-442
>             Project: Commons Net
>          Issue Type: Bug
>          Components: FTP
>    Affects Versions: 3.0.1
>         Environment: Ubuntu linux 11.04
>            Reporter: Andrea Selva
>
> 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);
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (NET-442) StringIndexOutOfBoundsException: String index out of range: -1 if server respond with root is current directory

Posted by "Sebb (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/NET-442?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13220251#comment-13220251 ] 

Sebb commented on NET-442:
--------------------------

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.
                
> StringIndexOutOfBoundsException: String index out of range: -1 if server respond with root is current directory
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: NET-442
>                 URL: https://issues.apache.org/jira/browse/NET-442
>             Project: Commons Net
>          Issue Type: Bug
>          Components: FTP
>    Affects Versions: 3.0.1
>         Environment: Ubuntu linux 11.04
>            Reporter: Andrea Selva
>
> 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);
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira