From e601dbd8e3f09eb24becca06eca5798aaee3f1df Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 31 Aug 2018 19:40:29 +0200 Subject: [PATCH] sftp: Use ssh_buffer_pack() in sftp_fstat() Signed-off-by: Andreas Schneider --- src/sftp.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/sftp.c b/src/sftp.c index 0ecc0cd6..20279307 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -3157,27 +3157,23 @@ sftp_attributes sftp_fstat(sftp_file file) return NULL; } - rc = ssh_buffer_allocate_size(buffer, - sizeof(uint32_t) * 2 + - ssh_string_len(file->handle)); - if (rc < 0) { + id = sftp_get_new_id(file->sftp); + + rc = ssh_buffer_pack(buffer, + "dS", + id, + file->handle); + if (rc != SSH_OK) { ssh_set_error_oom(file->sftp->session); ssh_buffer_free(buffer); return NULL; } - id = sftp_get_new_id(file->sftp); - if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 || - ssh_buffer_add_ssh_string(buffer, file->handle) < 0) { - ssh_set_error_oom(file->sftp->session); - ssh_buffer_free(buffer); - return NULL; - } - if (sftp_packet_write(file->sftp, SSH_FXP_FSTAT, buffer) < 0) { - ssh_buffer_free(buffer); - return NULL; - } + rc = sftp_packet_write(file->sftp, SSH_FXP_FSTAT, buffer); ssh_buffer_free(buffer); + if (rc < 0) { + return NULL; + } while (msg == NULL) { if (sftp_read_and_dispatch(file->sftp) < 0) {