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.
This commit is contained in:
Daniel Stenberg 2010-06-11 11:13:46 +02:00
parent c87a48ae4c
commit 3490b3fe10

View File

@ -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) {