mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 18:04:25 +09:00
sftp: Use ssh_buffer_pack() in sftp_setstat()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
40
src/sftp.c
40
src/sftp.c
@@ -2410,7 +2410,6 @@ int sftp_setstat(sftp_session sftp, const char *file, sftp_attributes attr)
|
|||||||
{
|
{
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
ssh_buffer buffer;
|
ssh_buffer buffer;
|
||||||
ssh_string path;
|
|
||||||
sftp_message msg = NULL;
|
sftp_message msg = NULL;
|
||||||
sftp_status_message status = NULL;
|
sftp_status_message status = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
@@ -2421,39 +2420,30 @@ int sftp_setstat(sftp_session sftp, const char *file, sftp_attributes attr)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
path = ssh_string_from_char(file);
|
|
||||||
if (path == NULL) {
|
|
||||||
ssh_set_error_oom(sftp->session);
|
|
||||||
ssh_buffer_free(buffer);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = ssh_buffer_allocate_size(buffer,
|
|
||||||
sizeof(uint32_t) * 2 +
|
|
||||||
ssh_string_len(path));
|
|
||||||
if (rc < 0) {
|
|
||||||
ssh_set_error_oom(sftp->session);
|
|
||||||
ssh_buffer_free(buffer);
|
|
||||||
ssh_string_free(path);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
id = sftp_get_new_id(sftp);
|
id = sftp_get_new_id(sftp);
|
||||||
if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
|
|
||||||
ssh_buffer_add_ssh_string(buffer, path) < 0 ||
|
rc = ssh_buffer_pack(buffer,
|
||||||
buffer_add_attributes(buffer, attr) < 0) {
|
"ds",
|
||||||
|
id,
|
||||||
|
file);
|
||||||
|
if (rc != SSH_OK) {
|
||||||
ssh_set_error_oom(sftp->session);
|
ssh_set_error_oom(sftp->session);
|
||||||
ssh_buffer_free(buffer);
|
ssh_buffer_free(buffer);
|
||||||
ssh_string_free(path);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (sftp_packet_write(sftp, SSH_FXP_SETSTAT, buffer) < 0) {
|
|
||||||
|
rc = buffer_add_attributes(buffer, attr);
|
||||||
|
if (rc != 0) {
|
||||||
|
ssh_set_error_oom(sftp->session);
|
||||||
ssh_buffer_free(buffer);
|
ssh_buffer_free(buffer);
|
||||||
ssh_string_free(path);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = sftp_packet_write(sftp, SSH_FXP_SETSTAT, buffer);
|
||||||
ssh_buffer_free(buffer);
|
ssh_buffer_free(buffer);
|
||||||
ssh_string_free(path);
|
if (rc < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
while (msg == NULL) {
|
while (msg == NULL) {
|
||||||
if (sftp_read_and_dispatch(sftp) < 0) {
|
if (sftp_read_and_dispatch(sftp) < 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user