mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-02 01:17:52 +03:00
Improve parse_status_msg().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@585 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -580,33 +580,45 @@ static inline u32 sftp_get_new_id(SFTP_SESSION *session) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static STATUS_MESSAGE *parse_status_msg(SFTP_MESSAGE *msg){
|
static STATUS_MESSAGE *parse_status_msg(SFTP_MESSAGE *msg){
|
||||||
STATUS_MESSAGE *status;
|
STATUS_MESSAGE *status;
|
||||||
if(msg->packet_type != SSH_FXP_STATUS){
|
|
||||||
ssh_set_error(msg->sftp->session, SSH_FATAL,"Not a ssh_fxp_status message passed in !");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = malloc(sizeof(STATUS_MESSAGE));
|
if (msg->packet_type != SSH_FXP_STATUS) {
|
||||||
if (status == NULL) {
|
ssh_set_error(msg->sftp->session, SSH_FATAL,
|
||||||
return NULL;
|
"Not a ssh_fxp_status message passed in!");
|
||||||
}
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
memset(status,0,sizeof(*status));
|
status = malloc(sizeof(STATUS_MESSAGE));
|
||||||
status->id=msg->id;
|
if (status == NULL) {
|
||||||
if( (buffer_get_u32(msg->payload,&status->status)!= 4)
|
return NULL;
|
||||||
|| !(status->error=buffer_get_ssh_string(msg->payload)) ||
|
}
|
||||||
!(status->lang=buffer_get_ssh_string(msg->payload))){
|
ZERO_STRUCTP(status);
|
||||||
if(status->error)
|
|
||||||
free(status->error);
|
status->id = msg->id;
|
||||||
/* status->lang never get allocated if something failed */
|
if ((buffer_get_u32(msg->payload,&status->status) != 4) ||
|
||||||
free(status);
|
(status->error = buffer_get_ssh_string(msg->payload)) == NULL ||
|
||||||
ssh_set_error(msg->sftp->session,SSH_FATAL,"invalid SSH_FXP_STATUS message");
|
(status->lang = buffer_get_ssh_string(msg->payload)) == NULL) {
|
||||||
return NULL;
|
string_free(status->error);
|
||||||
}
|
/* status->lang never get allocated if something failed */
|
||||||
status->status=ntohl(status->status);
|
SAFE_FREE(status);
|
||||||
status->errormsg=string_to_char(status->error);
|
ssh_set_error(msg->sftp->session, SSH_FATAL,
|
||||||
status->langmsg=string_to_char(status->lang);
|
"Invalid SSH_FXP_STATUS message");
|
||||||
return status;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
status->status = ntohl(status->status);
|
||||||
|
status->errormsg = string_to_char(status->error);
|
||||||
|
status->langmsg = string_to_char(status->lang);
|
||||||
|
if (status->errormsg == NULL || status->langmsg == NULL) {
|
||||||
|
string_free(status->error);
|
||||||
|
string_free(status->lang);
|
||||||
|
SAFE_FREE(status->errormsg);
|
||||||
|
SAFE_FREE(status->langmsg);
|
||||||
|
SAFE_FREE(status);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void status_msg_free(STATUS_MESSAGE *status){
|
static void status_msg_free(STATUS_MESSAGE *status){
|
||||||
|
|||||||
Reference in New Issue
Block a user