1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-11-21 14:00:51 +03:00

sftp: Prevent files from being skipped if the output buffer is too small (#746)

Notes:
LIBSSH2_ERROR_BUFFER_TOO_SMALL is returned if the buffer is too small
to contain a returned directory entry. On this condition we jump to the
label `end`. At this point the number of names left is decremented
despite no name being returned.

As suggested in #714, this commit moves the error label after the
decrement of `names_left`.

Fixes #714

Credit:
Co-authored-by: Gabriel Smith <gabriel.smith@precisionot.com>
This commit is contained in:
Gabriel Smith
2022-09-23 13:03:56 -04:00
committed by GitHub
parent 91adeae486
commit bd9c65d68c

View File

@@ -1852,11 +1852,11 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
handle->u.dir.next_name = (char *) s; handle->u.dir.next_name = (char *) s;
handle->u.dir.names_packet_len = names_packet_len; handle->u.dir.names_packet_len = names_packet_len;
end:
if((--handle->u.dir.names_left) == 0) if((--handle->u.dir.names_left) == 0)
LIBSSH2_FREE(session, handle->u.dir.names_packet); LIBSSH2_FREE(session, handle->u.dir.names_packet);
end:
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, _libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"libssh2_sftp_readdir_ex() return %d", "libssh2_sftp_readdir_ex() return %d",
filename_len); filename_len);