SFTP: fail init SFTP if session isn't authenticated

Alexander Lamaison filed bug #172
(http://trac.libssh2.org/ticket/172), and pointed out that SFTP
init would do bad if the session isn't yet authenticated at the
time of the call, so we now check for this situation and returns
an error if detected. Calling sftp_init() at this point is bad
usage to start with.
This commit is contained in:
Daniel Stenberg 2010-06-07 13:10:51 +02:00
parent f285438022
commit eeeebd02e7

View File

@ -716,6 +716,13 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
LIBSSH2_API LIBSSH2_SFTP *libssh2_sftp_init(LIBSSH2_SESSION *session)
{
LIBSSH2_SFTP *ptr;
if(!(session->state & LIBSSH2_STATE_AUTHENTICATED)) {
_libssh2_error(session, LIBSSH2_ERROR_INVAL,
"session not authenticated yet");
return NULL;
}
BLOCK_ADJUST_ERRNO(ptr, session, sftp_init(session));
return ptr;
}