From 3490b3fe10481857d305f131ad198adc260d6fb3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 11 Jun 2010 11:13:46 +0200 Subject: [PATCH] agent: make the code better deal with unexpected code flows agent->ops gets initialized by the libssh2_agent_connect() call but we need to make sure that we don't segfault even if a bad sequence of function calls is used. --- src/agent.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/agent.c b/src/agent.c index 975ffa5..e1715b1 100644 --- a/src/agent.c +++ b/src/agent.c @@ -376,9 +376,12 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, } /* Make sure to be re-called as a result of EAGAIN. */ - if (*transctx->request != SSH2_AGENTC_SIGN_REQUEST) { + if (*transctx->request != SSH2_AGENTC_SIGN_REQUEST) + return LIBSSH2_ERROR_BAD_USE; + + if (!agent->ops) + /* if no agent has been connected, bail out */ return LIBSSH2_ERROR_BAD_USE; - } rc = agent->ops->transact(agent, transctx); if (rc) { @@ -471,9 +474,12 @@ agent_list_identities(LIBSSH2_AGENT *agent) } /* Make sure to be re-called as a result of EAGAIN. */ - if (*transctx->request != SSH2_AGENTC_REQUEST_IDENTITIES) { + if (*transctx->request != SSH2_AGENTC_REQUEST_IDENTITIES) + return LIBSSH2_ERROR_BAD_USE; + + if (!agent->ops) + /* if no agent has been connected, bail out */ return LIBSSH2_ERROR_BAD_USE; - } rc = agent->ops->transact(agent, transctx); if (rc) {