From 7fb9c9193e73272fc9a639ea5054c10f59e66470 Mon Sep 17 00:00:00 2001 From: zengwefeng Date: Fri, 2 Sep 2022 15:37:02 +0800 Subject: [PATCH] sync some patches from upstream community --- ...rt-Add-errno-reset-with-strtoul-call.patch | 62 +++++++++++++++++++ ...eturned-in-ssh_userauth_try_publicke.patch | 27 ++++++++ ...ose-the-socket-if-it-was-set-via-opt.patch | 32 ++++++++++ ...nForward-to-not-set-sourcehost-to-NU.patch | 32 ++++++++++ ...gth-calculation-of-packet-in-sftp_wr.patch | 29 +++++++++ libssh.spec | 18 +++++- 6 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 backport-Add-errno-reset-with-strtoul-call.patch create mode 100644 backport-auth-Fix-error-returned-in-ssh_userauth_try_publicke.patch create mode 100644 backport-client-Do-not-close-the-socket-if-it-was-set-via-opt.patch create mode 100644 backport-libsshpp-Fix-openForward-to-not-set-sourcehost-to-NU.patch create mode 100644 backport-sftp-fix-the-length-calculation-of-packet-in-sftp_wr.patch diff --git a/backport-Add-errno-reset-with-strtoul-call.patch b/backport-Add-errno-reset-with-strtoul-call.patch new file mode 100644 index 0000000..3640682 --- /dev/null +++ b/backport-Add-errno-reset-with-strtoul-call.patch @@ -0,0 +1,62 @@ +From eb9dc8cfc45875ddf8dd193eb16e506937ce5355 Mon Sep 17 00:00:00 2001 +From: Norbert Pocs +Date: Tue, 7 Jun 2022 14:28:30 +0200 +Subject: [PATCH] Add errno reset with strtoul call + +Contaminated errno can happen before strtoul call, thereofore +cleaning it before the call. +The errno is not used for checking later in code if fail happens, +therefore cleaning it right after error. + +Signed-off-by: Norbert Pocs +Reviewed-by: Jakub Jelen +--- + src/misc.c | 4 ++++ + tests/pkd/pkd_util.c | 1 + + 2 files changed, 5 insertions(+) + +diff --git a/src/misc.c b/src/misc.c +index f7efb9df..e890e829 100644 +--- a/src/misc.c ++++ b/src/misc.c +@@ -1361,21 +1361,25 @@ int ssh_analyze_banner(ssh_session session, int server) + * 012345678901234567890 + */ + if (strlen(openssh) > 9) { ++ errno = 0; + major = strtoul(openssh + 8, &tmp, 10); + if ((tmp == (openssh + 8)) || + ((errno == ERANGE) && (major == ULONG_MAX)) || + ((errno != 0) && (major == 0)) || + ((major < 1) || (major > 100))) { + /* invalid major */ ++ errno = 0; + goto done; + } + ++ errno = 0; + minor = strtoul(openssh + 10, &tmp, 10); + if ((tmp == (openssh + 10)) || + ((errno == ERANGE) && (major == ULONG_MAX)) || + ((errno != 0) && (major == 0)) || + (minor > 100)) { + /* invalid minor */ ++ errno = 0; + goto done; + } + +diff --git a/tests/pkd/pkd_util.c b/tests/pkd/pkd_util.c +index 0e3b19b4..e8e6fbb7 100644 +--- a/tests/pkd/pkd_util.c ++++ b/tests/pkd/pkd_util.c +@@ -81,6 +81,7 @@ static int is_openssh_client_new_enough(void) { + ((major < 1) || (major > 100))) { + fprintf(stderr, "failed to parse OpenSSH client version, " + "errno %d\n", errno); ++ errno = 0; + goto errversion; + } + +-- +2.33.0 + diff --git a/backport-auth-Fix-error-returned-in-ssh_userauth_try_publicke.patch b/backport-auth-Fix-error-returned-in-ssh_userauth_try_publicke.patch new file mode 100644 index 0000000..69951a7 --- /dev/null +++ b/backport-auth-Fix-error-returned-in-ssh_userauth_try_publicke.patch @@ -0,0 +1,27 @@ +From f6ad8057a71e7a690d31d43c3797081ff544e3fd Mon Sep 17 00:00:00 2001 +From: Andreas Schneider +Date: Wed, 22 Jun 2022 15:22:37 +0200 +Subject: [PATCH] auth: Fix error returned in ssh_userauth_try_publickey() + +Signed-off-by: Andreas Schneider +Reviewed-by: Jakub Jelen +--- + src/auth.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/auth.c b/src/auth.c +index 2e48cfc6..6343c6a9 100644 +--- a/src/auth.c ++++ b/src/auth.c +@@ -518,7 +518,7 @@ int ssh_userauth_try_publickey(ssh_session session, + SSH_FATAL, + "Wrong state (%d) during pending SSH call", + session->pending_call_state); +- return SSH_ERROR; ++ return SSH_AUTH_ERROR; + } + + /* Check if the given public key algorithm is allowed */ +-- +2.33.0 + diff --git a/backport-client-Do-not-close-the-socket-if-it-was-set-via-opt.patch b/backport-client-Do-not-close-the-socket-if-it-was-set-via-opt.patch new file mode 100644 index 0000000..d6cf9a0 --- /dev/null +++ b/backport-client-Do-not-close-the-socket-if-it-was-set-via-opt.patch @@ -0,0 +1,32 @@ +From 4b20d7ad1882feafb28e4371cd7c7c1c9c499153 Mon Sep 17 00:00:00 2001 +From: Andreas Schneider +Date: Tue, 19 Apr 2022 16:22:12 +0200 +Subject: [PATCH] client: Do not close the socket if it was set via options + +Fixes #122 + +Signed-off-by: Andreas Schneider +Reviewed-by: Jakub Jelen +--- + src/client.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/src/client.c b/src/client.c +index 4e2a299d..a41764f1 100644 +--- a/src/client.c ++++ b/src/client.c +@@ -720,7 +720,10 @@ ssh_disconnect(ssh_session session) + } + + ssh_packet_send(session); +- ssh_socket_close(session->socket); ++ /* Do not close the socket, if the fd was set via options. */ ++ if (session->opts.fd == SSH_INVALID_SOCKET) { ++ ssh_socket_close(session->socket); ++ } + } + error: + session->recv_seq = 0; +-- +2.33.0 + diff --git a/backport-libsshpp-Fix-openForward-to-not-set-sourcehost-to-NU.patch b/backport-libsshpp-Fix-openForward-to-not-set-sourcehost-to-NU.patch new file mode 100644 index 0000000..aaea14d --- /dev/null +++ b/backport-libsshpp-Fix-openForward-to-not-set-sourcehost-to-NU.patch @@ -0,0 +1,32 @@ +From a889527c1b8f9831b47ceac510057585cdc81d39 Mon Sep 17 00:00:00 2001 +From: Andreas Schneider +Date: Wed, 15 Jun 2022 15:10:08 +0200 +Subject: [PATCH] libsshpp: Fix openForward to not set sourcehost to NULL by + default + +This parameter is required. + +Fixes #25 + +Signed-off-by: Andreas Schneider +Reviewed-by: Jakub Jelen +--- + include/libssh/libsshpp.hpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/include/libssh/libsshpp.hpp b/include/libssh/libsshpp.hpp +index a678d375..602c7aec 100644 +--- a/include/libssh/libsshpp.hpp ++++ b/include/libssh/libsshpp.hpp +@@ -523,7 +523,7 @@ public: + return ssh_channel_is_open(channel) != 0; + } + int openForward(const char *remotehost, int remoteport, +- const char *sourcehost=NULL, int localport=0){ ++ const char *sourcehost, int localport=0){ + int err=ssh_channel_open_forward(channel,remotehost,remoteport, + sourcehost, localport); + ssh_throw(err); +-- +2.33.0 + diff --git a/backport-sftp-fix-the-length-calculation-of-packet-in-sftp_wr.patch b/backport-sftp-fix-the-length-calculation-of-packet-in-sftp_wr.patch new file mode 100644 index 0000000..ba6aa61 --- /dev/null +++ b/backport-sftp-fix-the-length-calculation-of-packet-in-sftp_wr.patch @@ -0,0 +1,29 @@ +From 332f1c2e093de27e7fcfe22d80f0660c57e002eb Mon Sep 17 00:00:00 2001 +From: tatataeki +Date: Wed, 29 Jun 2022 14:20:48 +0800 +Subject: [PATCH] sftp: fix the length calculation of packet in sftp_write + +Signed-off-by: tatataeki +Reviewed-by: Andreas Schneider +Reviewed-by: Jakub Jelen +--- + src/sftp.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/sftp.c b/src/sftp.c +index b1fa931e..e01012a8 100644 +--- a/src/sftp.c ++++ b/src/sftp.c +@@ -2178,8 +2178,8 @@ ssize_t sftp_write(sftp_file file, const void *buf, size_t count) { + sftp_set_error(sftp, SSH_FX_FAILURE); + return -1; + } +- packetlen=ssh_buffer_get_len(buffer); + len = sftp_packet_write(file->sftp, SSH_FXP_WRITE, buffer); ++ packetlen=ssh_buffer_get_len(buffer); + SSH_BUFFER_FREE(buffer); + if (len < 0) { + return -1; +-- +2.33.0 + diff --git a/libssh.spec b/libssh.spec index 3c0c4c0..7d9cfd3 100644 --- a/libssh.spec +++ b/libssh.spec @@ -1,6 +1,6 @@ Name: libssh Version: 0.9.6 -Release: 2 +Release: 3 Summary: A library implementing the SSH protocol License: LGPLv2+ URL: http://www.libssh.org @@ -9,6 +9,12 @@ Source0: https://www.libssh.org/files/0.9/%{name}-%{version}.tar.xz Source1: https://www.libssh.org/files/0.9/%{name}-%{version}.tar.xz.asc Source2: https://cryptomilk.org/gpgkey-8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D.gpg#/%{name}.keyring +Patch0: backport-Add-errno-reset-with-strtoul-call.patch +Patch1: backport-auth-Fix-error-returned-in-ssh_userauth_try_publicke.patch +Patch2: backport-client-Do-not-close-the-socket-if-it-was-set-via-opt.patch +Patch3: backport-libsshpp-Fix-openForward-to-not-set-sourcehost-to-NU.patch +Patch4: backport-sftp-fix-the-length-calculation-of-packet-in-sftp_wr.patch + BuildRequires: cmake gcc-c++ gnupg2 openssl-devel pkgconfig zlib-devel BuildRequires: krb5-devel libcmocka-devel openssh-clients openssh-server BuildRequires: nmap-ncat @@ -93,6 +99,16 @@ popd %doc ChangeLog README %changelog +* Fri Sep 02 2022 zengweifeng - 0.9.6-3 +- Type:bugfix +- Id:NA +- SUG:NA +- DESC:add errno while reset with strtoul call + fix error returned in ssh_userauth_try_publicke + client do not close the socket if it was set via opt + fix openForward to not set sourcehost to NULL + fix the length calculation of packet in sftp_write + * Wed Mar 16 2022 xihaochen - 0.9.6-2 - Type:bugfix - Id:NA -- Gitee