diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2014-02-06 20:30:29 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2014-02-06 20:30:29 +0100 |
commit | 3e57b54688a9ac28d4fe0cfb4c5f82ac58e2a808 (patch) | |
tree | bc311d5643647a00517e150ccf98418a5acd2e45 /src/packet.c | |
parent | 2a183440c73504eb40c38ea7fe37cdaa80207d90 (diff) | |
download | libssh-3e57b54688a9ac28d4fe0cfb4c5f82ac58e2a808.tar.gz libssh-3e57b54688a9ac28d4fe0cfb4c5f82ac58e2a808.tar.xz libssh-3e57b54688a9ac28d4fe0cfb4c5f82ac58e2a808.zip |
packet: Improve readablity of packet decrypt.
After discussion with Aris and it was not obvious enough to understand
the issue we decided to refactor it.
Reviewd-by: Aris Adamantiadis <aris@0xbadc0de.be>
Diffstat (limited to 'src/packet.c')
-rw-r--r-- | src/packet.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/packet.c b/src/packet.c index e57e67ec..4aed2fac 100644 --- a/src/packet.c +++ b/src/packet.c @@ -152,7 +152,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user) const uint8_t *packet; int to_be_read; int rc; - uint32_t len, compsize, payloadsize, buffer_len; + uint32_t len, compsize, payloadsize; uint8_t padding; size_t processed = 0; /* number of byte processed from the callback */ @@ -251,13 +251,14 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user) * Decrypt the rest of the packet (blocksize bytes already * have been decrypted) */ + uint32_t buffer_len = buffer_get_rest_len(session->in_buffer); /* The following check avoids decrypting zero bytes */ - buffer_len = buffer_get_rest_len(session->in_buffer); - if (buffer_len != blocksize) { - rc = packet_decrypt(session, - ((uint8_t*)buffer_get_rest(session->in_buffer) + blocksize), - buffer_len - blocksize); + if (buffer_len > blocksize) { + uint8_t *payload = ((uint8_t*)buffer_get_rest(session->in_buffer) + blocksize); + uint32_t plen = buffer_len - blocksize; + + rc = packet_decrypt(session, payload, plen); if (rc < 0) { ssh_set_error(session, SSH_FATAL, "Decrypt error"); goto error; |