jkf         2005/03/14 11:19:20

  Modified:    src/main/org/apache/tools/ant/taskdefs/optional/net FTP.java
  Log:
  PR: 28797
  
  FTP list command could crash with an ArrayIndexOutOfBoundsException.
  
  Revision  Changes    Path
  1.66      +19 -16    
ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
  
  Index: FTP.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- FTP.java  4 Mar 2005 22:31:40 -0000       1.65
  +++ FTP.java  14 Mar 2005 19:19:20 -0000      1.66
  @@ -1861,31 +1861,34 @@
        * @throws BuildException in unknown circumstances
        */
       protected void listFile(FTPClient ftp, BufferedWriter bw, String 
filename)
  -         throws IOException, BuildException {
  +            throws IOException, BuildException {
           if (verbose) {
               log("listing " + filename);
           }
  +        FTPFile[] ftpfiles = ftp.listFiles(resolveFile(filename));
   
  -        FTPFile ftpfile = ftp.listFiles(resolveFile(filename))[0];
  -
  -        bw.write(ftpfile.toString());
  -        bw.newLine();
  -
  -        transferred++;
  +        if (ftpfiles != null && ftpfiles.length > 0) {
  +            bw.write(ftpfiles[0].toString());
  +            bw.newLine();
  +            transferred++;
  +        }
       }
   
   
       /**
        * Create the specified directory on the remote host.
  -     *
  -     * @param ftp The FTP client connection
  -     * @param dir The directory to create (format must be correct for host
  -     *      type)
  -     * @throws IOException  in unknown circumstances
  -     * @throws BuildException if ignoreNoncriticalErrors has not been set to 
true
  -     *         and a directory could not be created, for instance because it 
was
  -     *         already existing. Precisely, the codes 521, 550 and 553 will 
trigger
  -     *         a BuildException
  +     * 
  +     * @param ftp
  +     *            The FTP client connection
  +     * @param dir
  +     *            The directory to create (format must be correct for host 
type)
  +     * @throws IOException
  +     *             in unknown circumstances
  +     * @throws BuildException
  +     *             if ignoreNoncriticalErrors has not been set to true and a
  +     *             directory could not be created, for instance because it 
was
  +     *             already existing. Precisely, the codes 521, 550 and 553 
will
  +     *             trigger a BuildException
        */
       protected void makeRemoteDir(FTPClient ftp, String dir)
            throws IOException, BuildException {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to