mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 02:38:09 +09:00
sftp.c: Validate that the SSH session is in nonblocking mode
The sftp API functions cannot interoperate properly with a nonblocking ssh session. Therefore code has been added in sftp_new() due to which the function will return failure if the caller passes a non blocking session without even trying to connect. Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
committed by
Jakub Jelen
parent
c03d0d4823
commit
1a64c577f6
22
src/sftp.c
22
src/sftp.c
@@ -102,12 +102,21 @@ static void sftp_ext_free(sftp_ext ext)
|
|||||||
|
|
||||||
sftp_session sftp_new(ssh_session session)
|
sftp_session sftp_new(ssh_session session)
|
||||||
{
|
{
|
||||||
sftp_session sftp;
|
sftp_session sftp = NULL;
|
||||||
|
int rc;
|
||||||
|
|
||||||
if (session == NULL) {
|
if (session == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ssh_is_blocking(session)) {
|
||||||
|
ssh_set_error(session,
|
||||||
|
SSH_FATAL,
|
||||||
|
"The SSH session needs to be set to blocking mode for "
|
||||||
|
"SFTP to work correctly.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
sftp = calloc(1, sizeof(struct sftp_session_struct));
|
sftp = calloc(1, sizeof(struct sftp_session_struct));
|
||||||
if (sftp == NULL) {
|
if (sftp == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
@@ -140,11 +149,18 @@ sftp_session sftp_new(ssh_session session)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ssh_channel_open_session(sftp->channel)) {
|
/*
|
||||||
|
* The following two calls shouldn't return SSH_AGAIN
|
||||||
|
* as the code has validated above that the SSH session
|
||||||
|
* is in blocking mode.
|
||||||
|
*/
|
||||||
|
rc = ssh_channel_open_session(sftp->channel);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ssh_channel_request_sftp(sftp->channel)) {
|
rc = ssh_channel_request_sftp(sftp->channel);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user