aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Dunn <amdunn@gmail.com>2014-02-05 17:26:57 -0600
committerAndreas Schneider <asn@cryptomilk.org>2014-02-06 19:40:29 +0100
commitabe4ed0e7562b2d3adc9ac187ef0978c45a9a777 (patch)
tree50c740705cadf4ba16148621f0c16f914231d228
parente7f831f0a3368b9c39eb838bb2f6ca266cb8e62c (diff)
downloadlibssh-abe4ed0e7562b2d3adc9ac187ef0978c45a9a777.tar.gz
libssh-abe4ed0e7562b2d3adc9ac187ef0978c45a9a777.tar.xz
libssh-abe4ed0e7562b2d3adc9ac187ef0978c45a9a777.zip
packet_crypt: Make packet_{en,de}crypt fail consistently on len == 0
Right now the behavior of packet_{en,de}crypt on len == 0 depends on the behavior of malloc. Instead, make these consistently fail based on what I assume the desired behavior is due to the first error message in each. Signed-off-by: Alan Dunn <amdunn@gmail.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--src/packet_crypt.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/packet_crypt.c b/src/packet_crypt.c
index 50b81893..cb73e414 100644
--- a/src/packet_crypt.c
+++ b/src/packet_crypt.c
@@ -22,6 +22,7 @@
*/
#include "config.h"
+#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -59,6 +60,9 @@ uint32_t packet_decrypt_len(ssh_session session, char *crypted){
int packet_decrypt(ssh_session session, void *data,uint32_t len) {
struct ssh_cipher_struct *crypto = session->current_crypto->in_cipher;
char *out = NULL;
+
+ assert(len);
+
if(len % session->current_crypto->in_cipher->blocksize != 0){
ssh_set_error(session, SSH_FATAL, "Cryptographic functions must be set on at least one blocksize (received %d)",len);
return SSH_ERROR;
@@ -89,6 +93,8 @@ unsigned char *packet_encrypt(ssh_session session, void *data, uint32_t len) {
unsigned int finallen;
uint32_t seq;
+ assert(len);
+
if (!session->current_crypto) {
return NULL; /* nothing to do here */
}