Ticket #131 (closed defect: fixed)

Opened 8 years ago

Last modified 5 years ago

Error in sftp_readdir

Reported by: dietmar10 Owned by: bagder
Priority: normal Milestone:
Component: SFTP Version: 1.2.2
Keywords: Cc: dietmar10, bagder
Blocked By: Blocks:

Description

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

Attachments

sftp_patch.diff (1.1 KB) - added by dietmar10 8 years ago.
Unified diff output for added lines in sftp_readdir

Download all attachments as: .zip

Change History

comment:1 Changed 8 years ago by bagder

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!

Changed 8 years ago by dietmar10

Unified diff output for added lines in sftp_readdir

comment:2 Changed 8 years ago by dietmar10

Hi, see the requested unified diff as file attachment.

Best regards
Dietmar

comment:3 Changed 7 years ago by bagder

  • Version set to 1.2.2

comment:4 Changed 7 years ago by bagder

  • Milestone set to 1.2.6
  • Resolution set to fixed
  • Status changed from assigned to closed

I cleaned up the function and fixed your problem in commit e22cdcea77cc454b309b4555cb397047a16a64bc

comment:5 Changed 5 years ago by bagder

  • Milestone 1.2.6 deleted

Milestone 1.2.6 deleted

Note: See TracTickets for help on using tickets.