mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
sftpserver: allocate packet on sftp_server_new
Ensure sftp_server_new allocates the packet and payload as sftp_packet_read now expects the packet and payload to be pre-allocated. Similarly, ensure sftp_get_client_message does not free the packet. Signed-off-by: Alberto Aguirre <albaguirre@gmail.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
9adc2d36eb
commit
14f5624ff5
21
src/sftp.c
21
src/sftp.c
@@ -211,10 +211,31 @@ sftp_session sftp_server_new(ssh_session session, ssh_channel chan){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sftp->read_packet = calloc(1, sizeof(struct sftp_packet_struct));
|
||||||
|
if (sftp->read_packet == NULL) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
sftp->read_packet->payload = ssh_buffer_new();
|
||||||
|
if (sftp->read_packet->payload == NULL) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
sftp->session = session;
|
sftp->session = session;
|
||||||
sftp->channel = chan;
|
sftp->channel = chan;
|
||||||
|
|
||||||
return sftp;
|
return sftp;
|
||||||
|
|
||||||
|
error:
|
||||||
|
ssh_set_error_oom(session);
|
||||||
|
if (sftp->read_packet != NULL) {
|
||||||
|
if (sftp->read_packet->payload != NULL) {
|
||||||
|
ssh_buffer_free(sftp->read_packet->payload);
|
||||||
|
}
|
||||||
|
SAFE_FREE(sftp->read_packet);
|
||||||
|
}
|
||||||
|
SAFE_FREE(sftp);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sftp_server_init(sftp_session sftp){
|
int sftp_server_init(sftp_session sftp){
|
||||||
|
|||||||
@@ -232,8 +232,6 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sftp_packet_free(packet);
|
|
||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user