mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 10:40:27 +09:00
Add more error checks to sftp_get_message().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@576 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -323,29 +323,49 @@ static void sftp_message_free(SFTP_MESSAGE *msg) {
|
|||||||
|
|
||||||
static SFTP_MESSAGE *sftp_get_message(SFTP_PACKET *packet) {
|
static SFTP_MESSAGE *sftp_get_message(SFTP_PACKET *packet) {
|
||||||
SFTP_SESSION *sftp = packet->sftp;
|
SFTP_SESSION *sftp = packet->sftp;
|
||||||
SFTP_MESSAGE *msg=sftp_message_new(sftp);
|
SFTP_MESSAGE *msg = NULL;
|
||||||
|
|
||||||
sftp_enter_function();
|
sftp_enter_function();
|
||||||
|
|
||||||
|
msg = sftp_message_new(sftp);
|
||||||
|
if (msg == NULL) {
|
||||||
|
sftp_leave_function();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
msg->sftp = packet->sftp;
|
msg->sftp = packet->sftp;
|
||||||
msg->packet_type = packet->type;
|
msg->packet_type = packet->type;
|
||||||
|
|
||||||
if ((packet->type != SSH_FXP_STATUS) && (packet->type!=SSH_FXP_HANDLE) &&
|
if ((packet->type != SSH_FXP_STATUS) && (packet->type!=SSH_FXP_HANDLE) &&
|
||||||
(packet->type != SSH_FXP_DATA) && (packet->type != SSH_FXP_ATTRS)
|
(packet->type != SSH_FXP_DATA) && (packet->type != SSH_FXP_ATTRS) &&
|
||||||
&& (packet->type != SSH_FXP_NAME)){
|
(packet->type != SSH_FXP_NAME)) {
|
||||||
ssh_set_error(packet->sftp->session,SSH_FATAL,"get_message : unknown packet type %d\n",packet->type);
|
ssh_set_error(packet->sftp->session, SSH_FATAL,
|
||||||
|
"Unknown packet type %d", packet->type);
|
||||||
sftp_message_free(msg);
|
sftp_message_free(msg);
|
||||||
sftp_leave_function();
|
sftp_leave_function();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer_get_u32(packet->payload, &msg->id) != sizeof(u32)) {
|
if (buffer_get_u32(packet->payload, &msg->id) != sizeof(u32)) {
|
||||||
ssh_set_error(packet->sftp->session,SSH_FATAL,"invalid packet %d : no ID",packet->type);
|
ssh_set_error(packet->sftp->session, SSH_FATAL,
|
||||||
|
"Invalid packet %d: no ID", packet->type);
|
||||||
sftp_message_free(msg);
|
sftp_message_free(msg);
|
||||||
sftp_leave_function();
|
sftp_leave_function();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssh_log(packet->sftp->session, SSH_LOG_PACKET,
|
ssh_log(packet->sftp->session, SSH_LOG_PACKET,
|
||||||
"Packet with id %d type %d",
|
"Packet with id %d type %d",
|
||||||
msg->id,
|
msg->id,
|
||||||
msg->packet_type);
|
msg->packet_type);
|
||||||
buffer_add_data(msg->payload,buffer_get_rest(packet->payload),buffer_get_rest_len(packet->payload));
|
|
||||||
|
if (buffer_add_data(msg->payload, buffer_get_rest(packet->payload),
|
||||||
|
buffer_get_rest_len(packet->payload)) < 0) {
|
||||||
|
sftp_message_free(msg);
|
||||||
|
sftp_leave_function();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
sftp_leave_function();
|
sftp_leave_function();
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user