aboutsummaryrefslogtreecommitdiff
path: root/libssh/crypt.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-01 21:24:16 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-01 21:24:16 +0000
commit891539af6cbdbdfabb8d37fb491f7f8cadf9823c (patch)
tree1699cb47cd68dc35a972f8b5e1d834946c48d944 /libssh/crypt.c
parent1b627b386763e22a7b8f7a7c8de9610c1da56cd2 (diff)
downloadlibssh-891539af6cbdbdfabb8d37fb491f7f8cadf9823c.tar.gz
libssh-891539af6cbdbdfabb8d37fb491f7f8cadf9823c.tar.xz
libssh-891539af6cbdbdfabb8d37fb491f7f8cadf9823c.zip
Add memory error checks for crypto wrapper functions.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@330 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/crypt.c')
-rw-r--r--libssh/crypt.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/libssh/crypt.c b/libssh/crypt.c
index 75c22df..9d8fa0f 100644
--- a/libssh/crypt.c
+++ b/libssh/crypt.c
@@ -90,7 +90,10 @@ unsigned char * packet_encrypt(SSH_SESSION *session,void *data,u32 len){
#endif
out=malloc(len);
if(session->version==2){
- ctx=hmac_init(session->current_crypto->encryptMAC,20,HMAC_SHA1);
+ ctx = hmac_init(session->current_crypto->encryptMAC,20,HMAC_SHA1);
+ if (ctx == NULL) {
+ return NULL;
+ }
hmac_update(ctx,(unsigned char *)&seq,sizeof(u32));
hmac_update(ctx,data,len);
hmac_final(ctx,session->current_crypto->hmacbuf,&finallen);
@@ -115,12 +118,16 @@ unsigned char * packet_encrypt(SSH_SESSION *session,void *data,u32 len){
return NULL;
}
+/* TODO FIXME think about the return value isn't 0 enough and -1 on error */
int packet_hmac_verify(SSH_SESSION *session,BUFFER *buffer,unsigned char *mac){
HMACCTX ctx;
unsigned char hmacbuf[EVP_MAX_MD_SIZE];
unsigned int len;
u32 seq=htonl(session->recv_seq);
ctx=hmac_init(session->current_crypto->decryptMAC,20,HMAC_SHA1);
+ if (ctx == NULL) {
+ return -1;
+ }
hmac_update(ctx,(unsigned char *)&seq,sizeof(u32));
hmac_update(ctx,buffer_get(buffer),buffer_get_len(buffer));
hmac_final(ctx,hmacbuf,&len);