1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-27 13:21:11 +03:00

packets: Fix ssh_send_keepalive()

ssh_send_keepalive() should use global_request() to properly configure
the state machine for packet filtering.

Signed-off-by: Nicolas Viennot <nicolas@viennot.biz>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Nicolas Viennot
2018-11-18 20:54:13 -05:00
committed by Andreas Schneider
parent bb5d46c190
commit 59ada799d7
3 changed files with 14 additions and 27 deletions

View File

@@ -98,5 +98,9 @@ int ssh_channel_flush(ssh_channel channel);
uint32_t ssh_channel_new_id(ssh_session session);
ssh_channel ssh_channel_from_local(ssh_session session, uint32_t id);
void ssh_channel_do_free(ssh_channel channel);
int ssh_global_request(ssh_session session,
const char *request,
ssh_buffer buffer,
int reply);
#endif /* CHANNELS_H_ */

View File

@@ -2090,8 +2090,11 @@ static int ssh_global_request_termination(void *s){
* SSH_AGAIN if in nonblocking mode and call has
* to be done again.
*/
static int global_request(ssh_session session, const char *request,
ssh_buffer buffer, int reply) {
int ssh_global_request(ssh_session session,
const char *request,
ssh_buffer buffer,
int reply)
{
int rc;
switch (session->global_req_state) {
@@ -2222,7 +2225,7 @@ int ssh_channel_listen_forward(ssh_session session,
goto error;
}
pending:
rc = global_request(session, "tcpip-forward", buffer, 1);
rc = ssh_global_request(session, "tcpip-forward", buffer, 1);
/* TODO: FIXME no guarantee the last packet we received contains
* that info */
@@ -2302,7 +2305,7 @@ int ssh_channel_cancel_forward(ssh_session session,
goto error;
}
pending:
rc = global_request(session, "cancel-tcpip-forward", buffer, 1);
rc = ssh_global_request(session, "cancel-tcpip-forward", buffer, 1);
error:
ssh_buffer_free(buffer);

View File

@@ -1253,30 +1253,10 @@ int ssh_execute_message_callbacks(ssh_session session){
int ssh_send_keepalive(ssh_session session)
{
int rc;
/* Client denies the request, so the error code is not meaningful */
(void)ssh_global_request(session, "keepalive@openssh.com", NULL, 1);
rc = ssh_buffer_pack(session->out_buffer,
"bsb",
SSH2_MSG_GLOBAL_REQUEST,
"keepalive@openssh.com",
1);
if (rc != SSH_OK) {
goto err;
}
if (ssh_packet_send(session) == SSH_ERROR) {
goto err;
}
ssh_handle_packets(session, SSH_TIMEOUT_NONBLOCKING);
SSH_LOG(SSH_LOG_PACKET, "Sent a keepalive");
return SSH_OK;
err:
ssh_set_error_oom(session);
ssh_buffer_reinit(session->out_buffer);
return SSH_ERROR;
}
/** @} */