mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-08 19:02:06 +03:00
channel: Reinit the buffer and reset the state on error.
BUG: https://red.libssh.org/issues/126
This commit is contained in:
@@ -2092,41 +2092,64 @@ static int ssh_global_request_termination(void *s){
|
|||||||
static int global_request(ssh_session session, const char *request,
|
static int global_request(ssh_session session, const char *request,
|
||||||
ssh_buffer buffer, int reply) {
|
ssh_buffer buffer, int reply) {
|
||||||
ssh_string req = NULL;
|
ssh_string req = NULL;
|
||||||
int rc = SSH_ERROR;
|
int rc;
|
||||||
|
|
||||||
if(session->global_req_state != SSH_CHANNEL_REQ_STATE_NONE)
|
switch (session->global_req_state) {
|
||||||
|
case SSH_CHANNEL_REQ_STATE_NONE:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
goto pending;
|
goto pending;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = buffer_add_u8(session->out_buffer, SSH2_MSG_GLOBAL_REQUEST);
|
||||||
|
if (rc < 0) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
req = ssh_string_from_char(request);
|
req = ssh_string_from_char(request);
|
||||||
if (req == NULL) {
|
if (req == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
|
rc = SSH_ERROR;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer_add_u8(session->out_buffer, SSH2_MSG_GLOBAL_REQUEST) < 0 ||
|
rc = buffer_add_ssh_string(session->out_buffer, req);
|
||||||
buffer_add_ssh_string(session->out_buffer, req) < 0 ||
|
ssh_string_free(req);
|
||||||
buffer_add_u8(session->out_buffer, reply == 0 ? 0 : 1) < 0) {
|
if (rc < 0) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
|
rc = SSH_ERROR;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = buffer_add_u8(session->out_buffer, reply == 0 ? 0 : 1);
|
||||||
|
if (rc < 0) {
|
||||||
|
ssh_set_error_oom(session);
|
||||||
|
rc = SSH_ERROR;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
ssh_string_free(req);
|
|
||||||
req=NULL;
|
|
||||||
|
|
||||||
if (buffer != NULL) {
|
if (buffer != NULL) {
|
||||||
if (buffer_add_data(session->out_buffer, buffer_get_rest(buffer),
|
rc = buffer_add_data(session->out_buffer,
|
||||||
buffer_get_rest_len(buffer)) < 0) {
|
buffer_get_rest(buffer),
|
||||||
|
buffer_get_rest_len(buffer));
|
||||||
|
if (rc < 0) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
|
rc = SSH_ERROR;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session->global_req_state = SSH_CHANNEL_REQ_STATE_PENDING;
|
session->global_req_state = SSH_CHANNEL_REQ_STATE_PENDING;
|
||||||
if (packet_send(session) == SSH_ERROR) {
|
rc = packet_send(session);
|
||||||
|
if (rc == SSH_ERROR) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSH_LOG(SSH_LOG_PACKET,
|
SSH_LOG(SSH_LOG_PACKET,
|
||||||
"Sent a SSH_MSG_GLOBAL_REQUEST %s", request);
|
"Sent a SSH_MSG_GLOBAL_REQUEST %s", request);
|
||||||
|
|
||||||
if (reply == 0) {
|
if (reply == 0) {
|
||||||
session->global_req_state=SSH_CHANNEL_REQ_STATE_NONE;
|
session->global_req_state = SSH_CHANNEL_REQ_STATE_NONE;
|
||||||
|
|
||||||
return SSH_OK;
|
return SSH_OK;
|
||||||
}
|
}
|
||||||
@@ -2153,16 +2176,16 @@ pending:
|
|||||||
break;
|
break;
|
||||||
case SSH_CHANNEL_REQ_STATE_ERROR:
|
case SSH_CHANNEL_REQ_STATE_ERROR:
|
||||||
case SSH_CHANNEL_REQ_STATE_NONE:
|
case SSH_CHANNEL_REQ_STATE_NONE:
|
||||||
rc=SSH_ERROR;
|
rc = SSH_ERROR;
|
||||||
break;
|
break;
|
||||||
case SSH_CHANNEL_REQ_STATE_PENDING:
|
case SSH_CHANNEL_REQ_STATE_PENDING:
|
||||||
rc=SSH_AGAIN;
|
return SSH_AGAIN;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
session->global_req_state = SSH_CHANNEL_REQ_STATE_NONE;
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
error:
|
error:
|
||||||
ssh_string_free(req);
|
buffer_reinit(session->out_buffer);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user