Bugs item #2912831, was opened at 2009-12-11 19:28
Message generated for change (Comment added) made by dietmar10
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=703942&aid=2912831&group_id=125852
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: SFTP
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Dietmar Dreyer (dietmar10)
Assigned to: Daniel Stenberg (bagder)
Summary: Error in sftp_readdir
Initial Comment:
Hi!
I encountered an error in function sftp_readdir in libssh2-1.2.2. The 4th
argument longentry is ignored when a directory contains exactly one single
entry. Looking at the code, it seems that the handling of the longentry in this
case has just been forgotten.
As a quick workaround, I inserted following code in file sftp.c, function
sftp_readdir(...) in line 1365.
if (num_names == 1) {
unsigned long real_filename_len = _libssh2_ntohu32(data + 9);
filename_len = real_filename_len;
if (filename_len > buffer_maxlen) {
filename_len = buffer_maxlen;
}
memcpy(buffer, data + 13, filename_len);
/* The filename is not null terminated, make it so if possible */
if (filename_len < buffer_maxlen) {
buffer[filename_len] = '\0';
}
/* <BUGFIX> Longentry not handled so far */
if ((longentry != NULL) && (longentry_maxlen > 0))
{
unsigned long real_longentry_len =
_libssh2_ntohu32(data + 13 + real_filename_len);
longentry_len = real_longentry_len;
//s += 4;
if (longentry_len > longentry_maxlen)
{
longentry_len = longentry_maxlen;
}
memcpy(longentry, data+4+13 + real_filename_len,
longentry_len);
//s += real_longentry_len;
/* The longentry is not null terminated, make it so if
possible */
if (longentry_len < longentry_maxlen) {
longentry[longentry_len] = '\0';
}
}
/***************************************************/
if (attrs) {
memset(attrs, 0, sizeof(LIBSSH2_SFTP_ATTRIBUTES));
sftp_bin2attr(attrs, data + 13 + real_filename_len +
(4 + _libssh2_ntohu32(data + 13 +
real_filename_len)));
}
Hope, this helps
----------------------------------------------------------------------
>Comment By: Dietmar Dreyer (dietmar10)
Date: 2009-12-13 15:14
Message:
Hi, see the requested unified diff as file attachment.
Best regards
Dietmar
----------------------------------------------------------------------
Comment By: Daniel Stenberg (bagder)
Date: 2009-12-11 22:27
Message:
Can you please provide your suggested fix as a diff -u output? It'll make
life much easier in our ends. Preferably attached to this issue?
Thanks a lot for your contribution and help in improving libssh2!
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=703942&aid=2912831&group_id=125852
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel