aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Simons <jon@jonsimons.org>2014-02-06 12:37:02 -0800
committerAndreas Schneider <asn@cryptomilk.org>2014-03-27 11:25:15 +0100
commit34ac4e42486029a75a8dc74eb328459b3cc656c0 (patch)
tree5817e70892d65e616e6799b6a5181f871aa5f0b9
parent1928fb6a85c14ceed2cd63b30ce1987eba576555 (diff)
downloadlibssh-34ac4e42486029a75a8dc74eb328459b3cc656c0.tar.gz
libssh-34ac4e42486029a75a8dc74eb328459b3cc656c0.tar.xz
libssh-34ac4e42486029a75a8dc74eb328459b3cc656c0.zip
packet: elide two buffer_prepend calls into one
In packet_send2, rather than issue two separate buffer_prepend_data calls (each of which may entail realloc + memmove + memcpy), elide the prepend work into a single buffer_prepend_data: the header information is computed locally, and a single 5 byte prepend operation is now done instead of prepending 1, then 4 bytes. Reviewed-by: Andreas Schneider <asn@cryptomilk.org> (cherry picked from commit aa05248ca81e3bd9e949ad724d45518707446e2c) Conflicts: src/packet.c
-rw-r--r--src/packet.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/packet.c b/src/packet.c
index 96f6d10f..535b6d55 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -504,11 +504,13 @@ static int packet_send2(ssh_session session) {
session->current_crypto->out_cipher->blocksize : 8);
uint32_t currentlen = buffer_get_rest_len(session->out_buffer);
unsigned char *hmac = NULL;
- char padstring[32] = {0};
+ char padstring[32] = { 0 };
int rc = SSH_ERROR;
uint32_t finallen,payloadsize,compsize;
uint8_t padding;
+ uint8_t header[sizeof(padding) + sizeof(finallen)] = { 0 };
+
payloadsize = currentlen;
#ifdef WITH_ZLIB
if (session->current_crypto
@@ -528,19 +530,18 @@ static int packet_send2(ssh_session session) {
if (session->current_crypto) {
ssh_get_random(padstring, padding, 0);
- } else {
- memset(padstring,0,padding);
}
finallen = htonl(currentlen + padding + 1);
- if (buffer_prepend_data(session->out_buffer, &padding, sizeof(uint8_t)) < 0) {
- goto error;
- }
- if (buffer_prepend_data(session->out_buffer, &finallen, sizeof(uint32_t)) < 0) {
+ memcpy(&header[0], &finallen, sizeof(finallen));
+ header[sizeof(finallen)] = padding;
+ rc = buffer_prepend_data(session->out_buffer, &header, sizeof(header));
+ if (rc < 0) {
goto error;
}
- if (buffer_add_data(session->out_buffer, padstring, padding) < 0) {
+ rc = buffer_add_data(session->out_buffer, padstring, padding);
+ if (rc < 0) {
goto error;
}
#ifdef WITH_PCAP