From bdaa6dd5ba9ad63379c73b53fc639ea39df505c4 Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <daniel@haxx.se>
Date: Sun, 16 Oct 2022 12:58:55 +0200
Subject: [PATCH] libssh: if sftp_init fails, don't get the sftp error code

This flow extracted the wrong code (sftp code instead of ssh code), and
the code is sometimes (erroneously) returned as zero anyway, so skip
getting it and set a generic error.

Reported-by: David McLaughlin
Fixes #9737
Closes #9740

Conflict: NA
Reference: https://github.com/curl/curl/commit/bdaa6dd5ba9ad63379c73b53fc639ea39df505c4
---
 lib/vssh/libssh.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c
index 1afadbfa5..0105e4079 100644
--- a/lib/vssh/libssh.c
+++ b/lib/vssh/libssh.c
@@ -963,10 +963,9 @@ static CURLcode myssh_statemach_act(struct Curl_easy *data, bool *block)
 
       rc = sftp_init(sshc->sftp_session);
       if(rc != SSH_OK) {
-        rc = sftp_get_error(sshc->sftp_session);
         failf(data, "Failure initializing sftp session: %s",
               ssh_get_error(sshc->ssh_session));
-        MOVE_TO_ERROR_STATE(sftp_error_to_CURLE(rc));
+        MOVE_TO_ERROR_STATE(sftp_error_to_CURLE(SSH_FX_FAILURE));
         break;
       }
       state(data, SSH_SFTP_REALPATH);
-- 
2.33.0

