[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] crypto: check malloc return in ssh_mac_ctx_init
[Thread Prev] | [Thread Next]
- Subject: [PATCH] crypto: check malloc return in ssh_mac_ctx_init
- From: Jon Simons <jon@xxxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Fri, 26 Sep 2014 21:20:46 -0700
- To: libssh@xxxxxxxxxx
Attached is a fix for an unchecked malloc in 'ssh_mac_ctx_init'. -Jon
From 4bdf5f91b5d2b7580c4493300b97fe02b865bc7d Mon Sep 17 00:00:00 2001 From: Jon Simons <jon@xxxxxxxxxxxxx> Date: Fri, 26 Sep 2014 21:13:01 -0700 Subject: [PATCH] crypto: check malloc return in ssh_mac_ctx_init Signed-off-by: Jon Simons <jon@xxxxxxxxxxxxx> --- src/libcrypto.c | 6 +++++- src/libgcrypt.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libcrypto.c b/src/libcrypto.c index 84afbb0..479c8c1 100644 --- a/src/libcrypto.c +++ b/src/libcrypto.c @@ -250,7 +250,11 @@ void md5_final(unsigned char *md, MD5CTX c) { } ssh_mac_ctx ssh_mac_ctx_init(enum ssh_mac_e type){ - ssh_mac_ctx ctx=malloc(sizeof(struct ssh_mac_ctx_struct)); + ssh_mac_ctx ctx = malloc(sizeof(struct ssh_mac_ctx_struct)); + if (ctx == NULL) { + return NULL; + } + ctx->mac_type=type; switch(type){ case SSH_MAC_SHA1: diff --git a/src/libgcrypt.c b/src/libgcrypt.c index 6151cfa..24d4a3c 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -150,7 +150,11 @@ void md5_final(unsigned char *md, MD5CTX c) { } ssh_mac_ctx ssh_mac_ctx_init(enum ssh_mac_e type){ - ssh_mac_ctx ctx=malloc(sizeof(struct ssh_mac_ctx_struct)); + ssh_mac_ctx ctx = malloc(sizeof(struct ssh_mac_ctx_struct)); + if (ctx == NULL) { + return NULL; + } + ctx->mac_type=type; switch(type){ case SSH_MAC_SHA1: -- 2.1.1.602.g02f248d
Archive administrator: postmaster@lists.cynapses.org