From 1cccfdf8a0003dec18b00ff75f6c608bf6039e25 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 6 Feb 2014 20:30:29 +0100 Subject: 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 --- src/packet.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/packet.c b/src/packet.c index ffd08d06..96f6d10f 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; -- cgit v1.2.3