aboutsummaryrefslogtreecommitdiff
path: root/src/agent.c
diff options
context:
space:
mode:
authorPino Toscano <ptoscano@redhat.com>2018-06-27 14:10:26 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-08-01 11:04:33 +0200
commit12284b75fa5e5f6439223c07cbeb49a5eadc9c6b (patch)
tree028c4c036d3d37ce32b7812b8aa6d7d948ca6a2b /src/agent.c
parentafa4021ded6e58da4ee4d01dbf4e503d3711d002 (diff)
downloadlibssh-12284b75fa5e5f6439223c07cbeb49a5eadc9c6b.tar.gz
libssh-12284b75fa5e5f6439223c07cbeb49a5eadc9c6b.tar.xz
libssh-12284b75fa5e5f6439223c07cbeb49a5eadc9c6b.zip
buffer: Add and use ssh_buffer_allocate_size()
Add a small helper for ssh_buffer to ensure that the buffer has a certain amount of space already preallocated. This can be useful in case it is known how much data is going to be added to a buffer, to avoid multiple reallocations. Make use of it in few places in the library. Signed-off-by: Pino Toscano <ptoscano@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/agent.c')
-rw-r--r--src/agent.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/agent.c b/src/agent.c
index 2b063074..114dadf1 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -514,6 +514,21 @@ ssh_string ssh_agent_sign_data(ssh_session session,
return NULL;
}
+ /*
+ * make sure it already can contain all the expected content:
+ * - 1 x uint8_t
+ * - 2 x uint32_t
+ * - 1 x ssh_string (uint8_t + data)
+ */
+ rc = ssh_buffer_allocate_size(request,
+ sizeof(uint8_t) * 2 +
+ sizeof(uint32_t) * 2 +
+ ssh_string_len(key_blob));
+ if (rc < 0) {
+ ssh_buffer_free(request);
+ return NULL;
+ }
+
/* adds len + blob */
rc = ssh_buffer_add_ssh_string(request, key_blob);
ssh_string_free(key_blob);