Hey Guys,

I've found (and fixed) a bug in the jsch SFTP code that parses the
file type attributes returned from the server.  The bit masking logic
is not quite correct.  This will manifest itself by incorrectly
labeling a socket file type as a directory.  To reproduce the problem,
just use the ChannelSftp class to list a file on the server that is a
socket, and call the isDir() method from the SftpATTRS class.  The
value of isDir() will be true, but it should be false.  For a possible
test case, there is a socket file on my Ubuntu box named:
/var/run/acpid.socket.

Here's a patch to correct the problem.  It's modeled after the POSIX
stat functionality in linux, found on my machine in the files
/usr/include/bits/stat.h and /usr/include/sys/stat.h.  Let me know if
this needs further clarification or if there are any other questions.

Regards,
Peter

----------------------------------

diff -Nur jsch-0.1.44/src/com/jcraft/jsch/SftpATTRS.java
jsch-0.1.44-mod/src/com/jcraft/jsch/SftpATTRS.java
--- jsch-0.1.44/src/com/jcraft/jsch/SftpATTRS.java      2010-03-05
03:04:46.000000000 -0500
+++ jsch-0.1.44-mod/src/com/jcraft/jsch/SftpATTRS.java  2011-02-16
00:34:10.000000000 -0500
@@ -123,6 +123,7 @@
   public static final int SSH_FILEXFER_ATTR_ACMODTIME=    0x00000008;
   public static final int SSH_FILEXFER_ATTR_EXTENDED=     0x80000000;

+  static final int S_IFMT= 0xF000;
   static final int S_IFDIR=0x4000;
   static final int S_IFLNK=0xa000;

@@ -233,11 +234,11 @@

   public boolean isDir(){
     return ((flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0 &&
-           ((permissions&S_IFDIR)==S_IFDIR));
+           ((permissions&S_IFMT)==S_IFDIR));
   }
   public boolean isLink(){
     return ((flags&SSH_FILEXFER_ATTR_PERMISSIONS)!=0 &&
-           ((permissions&S_IFLNK)==S_IFLNK));
+           ((permissions&S_IFMT)==S_IFLNK));
   }
   public int getFlags() { return flags; }
   public long getSize() { return size; }

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to