From f1e84d5e67e76c003d7ae375a7e3a00e13c0fa57 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Fri, 31 Aug 2018 19:05:53 +0200
Subject: [PATCH] sftp: Use ssh_buffer_pack() in sftp_fsync()

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
---
 src/sftp.c | 35 +++++------------------------------
 1 file changed, 5 insertions(+), 30 deletions(-)

diff --git a/src/sftp.c b/src/sftp.c
index d50d48d4..9c2bb90d 100644
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -2811,7 +2811,6 @@ int sftp_fsync(sftp_file file)
 {
     sftp_session sftp;
     sftp_message msg = NULL;
-    ssh_string ext;
     ssh_buffer buffer;
     uint32_t id;
     int rc;
@@ -2827,36 +2826,13 @@ int sftp_fsync(sftp_file file)
         return -1;
     }
 
-    ext = ssh_string_from_char("fsync@openssh.com");
-    if (ext == NULL) {
-        ssh_set_error_oom(sftp->session);
-        rc = -1;
-        goto done;
-    }
-
-    rc = ssh_buffer_allocate_size(buffer,
-                                        sizeof(uint32_t) * 3 +
-                                        ssh_string_len(ext) +
-                                        ssh_string_len(file->handle));
-    if (rc < 0) {
-        ssh_set_error_oom(sftp->session);
-        goto done;
-    }
-
     id = sftp_get_new_id(sftp);
-    rc = ssh_buffer_add_u32(buffer, htonl(id));
-    if (rc < 0) {
-        ssh_set_error_oom(sftp->session);
-        goto done;
-    }
 
-    rc = ssh_buffer_add_ssh_string(buffer, ext);
-    if (rc < 0) {
-        ssh_set_error_oom(sftp->session);
-        goto done;
-    }
-
-    rc = ssh_buffer_add_ssh_string(buffer, file->handle);
+    rc = ssh_buffer_pack(buffer,
+                         "dsS",
+                         id,
+                         "fsync@openssh.com",
+                         file->handle);
     if (rc < 0) {
         ssh_set_error_oom(sftp->session);
         goto done;
@@ -2923,7 +2899,6 @@ int sftp_fsync(sftp_file file)
     rc = -1;
 done:
     ssh_buffer_free(buffer);
-    ssh_string_free(ext);
 
     return rc;
 }