Bugs item #2912831, was opened at 2009-12-11 19:28
Message generated for change (Tracker Item Submitted) 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: Nobody/Anonymous (nobody)
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

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

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

Reply via email to