From c82c833f1baa2af27fb96d1c34ed73017173b5a8 Mon Sep 17 00:00:00 2001 From: renmingshuai Date: Wed, 19 Oct 2022 09:50:35 +0800 Subject: [PATCH] sftp:Prevent files from being skipped if the output buffer is too small Signed-off-by: renmingshuai --- ...vent-files-from-being-skipped-if-the.patch | 45 +++++++++++++++++++ libssh2.spec | 9 +++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 backport-sftp-Prevent-files-from-being-skipped-if-the.patch diff --git a/backport-sftp-Prevent-files-from-being-skipped-if-the.patch b/backport-sftp-Prevent-files-from-being-skipped-if-the.patch new file mode 100644 index 0000000..c8584fc --- /dev/null +++ b/backport-sftp-Prevent-files-from-being-skipped-if-the.patch @@ -0,0 +1,45 @@ +From bd9c65d68c4152ba0726f5588b4b611410972fbc Mon Sep 17 00:00:00 2001 +From: Gabriel Smith +Date: Fri, 23 Sep 2022 13:03:56 -0400 +Subject: [PATCH] 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 +Conflict:NA +Reference:https://github.com/libssh2/libssh2/commit/bd9c65d68c +--- + src/sftp.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/sftp.c b/src/sftp.c +index b1a5352..2df918a 100644 +--- a/src/sftp.c ++++ b/src/sftp.c +@@ -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.names_packet_len = names_packet_len; +- end: + + if((--handle->u.dir.names_left) == 0) + LIBSSH2_FREE(session, handle->u.dir.names_packet); + ++ end: + _libssh2_debug(session, LIBSSH2_TRACE_SFTP, + "libssh2_sftp_readdir_ex() return %d", + filename_len); +-- +2.25.1 + diff --git a/libssh2.spec b/libssh2.spec index de6a2a4..7d3280c 100644 --- a/libssh2.spec +++ b/libssh2.spec @@ -1,12 +1,13 @@ Name: libssh2 Version: 1.10.0 -Release: 2 +Release: 3 Summary: A library implementing the SSH2 protocol License: BSD URL: https://www.libssh2.org/ Source0: https://libssh2.org/download/libssh2-%{version}.tar.gz Patch0: backport-RSA-SHA2-256-512-key-upgrade-support-RFC-8332.patch +Patch1: backport-sftp-Prevent-files-from-being-skipped-if-the.patch BuildRequires: coreutils findutils /usr/bin/man zlib-devel BuildRequires: gcc make sed openssl-devel > 1:1.0.1 openssh-server @@ -86,6 +87,12 @@ LC_ALL=en_US.UTF-8 make -C tests check %{_mandir}/man3/libssh2_*.3* %changelog +* Wed Oct 19 2022 renmingshuai - 1.10.0-3 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:sftp:Prevent files from being skipped + * Fri Jan 07 2022 xingwei - 1.10.0-2 - Type:bugfix - ID:NA -- Gitee