Commit 59ada799 authored by Nicolas Viennot's avatar Nicolas Viennot Committed by Andreas Schneider
Browse files

packets: Fix ssh_send_keepalive()



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

Signed-off-by: default avatarNicolas Viennot <nicolas@viennot.biz>
Reviewed-by: default avatarAndreas Schneider <asn@cryptomilk.org>
parent bb5d46c1
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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_ */
+7 −4
Original line number Diff line number Diff line
@@ -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);
+3 −23
Original line number Diff line number Diff line
@@ -1253,30 +1253,10 @@ int ssh_execute_message_callbacks(ssh_session session){

int ssh_send_keepalive(ssh_session session)
{
  int rc;

  rc = ssh_buffer_pack(session->out_buffer,
                       "bsb",
                       SSH2_MSG_GLOBAL_REQUEST,
                       "keepalive@openssh.com",
                       1);
  if (rc != SSH_OK) {
    goto err;
  }
    /* Client denies the request, so the error code is not meaningful */
    (void)ssh_global_request(session, "keepalive@openssh.com", NULL, 1);

  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;
}

/** @} */