aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2014-02-06 20:30:29 +0100
committerAndreas Schneider <asn@cryptomilk.org>2014-02-06 20:32:05 +0100
commit1cccfdf8a0003dec18b00ff75f6c608bf6039e25 (patch)
tree067c6c84c904ef4f1b371ad66a119203958d94b3
parentabe4ed0e7562b2d3adc9ac187ef0978c45a9a777 (diff)
downloadlibssh-1cccfdf8a0003dec18b00ff75f6c608bf6039e25.tar.gz
libssh-1cccfdf8a0003dec18b00ff75f6c608bf6039e25.tar.xz
libssh-1cccfdf8a0003dec18b00ff75f6c608bf6039e25.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>
-rw-r--r--src/packet.c13
1 files 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;