diff --git a/src/sftp.c b/src/sftp.c index 27cb4553..1fc2b208 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -3071,7 +3071,6 @@ static sftp_attributes sftp_xstat(sftp_session sftp, { sftp_status_message status = NULL; sftp_message msg = NULL; - ssh_string pathstr; ssh_buffer buffer; uint32_t id; int rc; @@ -3087,38 +3086,23 @@ static sftp_attributes sftp_xstat(sftp_session sftp, return NULL; } - pathstr = ssh_string_from_char(path); - if (pathstr == NULL) { - ssh_set_error_oom(sftp->session); - ssh_buffer_free(buffer); - return NULL; - } - - rc = ssh_buffer_allocate_size(buffer, - sizeof(uint32_t) * 2 + - ssh_string_len(pathstr)); - if (rc < 0) { - ssh_set_error_oom(sftp->session); - ssh_buffer_free(buffer); - ssh_string_free(pathstr); - return NULL; - } - id = sftp_get_new_id(sftp); - if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 || - ssh_buffer_add_ssh_string(buffer, pathstr) < 0) { + + rc = ssh_buffer_pack(buffer, + "ds", + id, + path); + if (rc != SSH_OK) { ssh_set_error_oom(sftp->session); ssh_buffer_free(buffer); - ssh_string_free(pathstr); - return NULL; - } - if (sftp_packet_write(sftp, param, buffer) < 0) { - ssh_buffer_free(buffer); - ssh_string_free(pathstr); return NULL; } + + rc = sftp_packet_write(sftp, param, buffer); ssh_buffer_free(buffer); - ssh_string_free(pathstr); + if (rc < 0) { + return NULL; + } while (msg == NULL) { if (sftp_read_and_dispatch(sftp) < 0) {