From eeeebd02e7fddd36544c525e75e66b035c5dad82 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 7 Jun 2010 13:10:51 +0200 Subject: [PATCH] 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. --- src/sftp.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/sftp.c b/src/sftp.c index 95b5802..8d00225 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -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; }