Ticket #6 (closed defect)
Opened 7 years ago
Last modified 6 years ago
Bug in libssh2_sftp_rename_ex
| Reported by: | ericpar | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Version: | ||
| Keywords: | Cc: | ericpar, sarag | |
| Blocked By: | Blocks: |
Description
libssh2_sftp_rename_ex fails for servers that implement
SFTP protocol version < 5. Furthermore, all SFTP
functions fail after a call to libssh2_sftp_rename_ex().
The problem is in the definition of the local variable
"packet_len" near the top of the function. It reserves
an extra 4 bytes for the rename flags, but these flags
are only used for SFTP version 5 or above. The code
that reads:
if (sftp->version >= 5) {
libssh2_htonu32(s, flags); s += 4;
}
never gets executed, thus "packet_len" and "s - packet"
differ by 4 bytes and the call to libssh2_channel_write
fails further in the function.
A simple fix is to change the definition of packet_len to:
unsigned long packet_len = source_filename_len +
dest_filename_len + 17;
/* packet_len(4) + packet_type(1) + request_id(4) +
source_filename_len(4) + dest_filename_len(4) */
and then add right below:
if (sftp->version >= 5) {
packet_len += 4; /* flags */
}

'twas fixed in Rel 0.12 (just now closing report)
Thanks