summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Simons <jon@jonsimons.org>2014-09-26 21:13:01 -0700
committerAndreas Schneider <asn@cryptomilk.org>2014-10-02 08:26:08 +0200
commitb7856780a932df08963587ab763a6ef17af90045 (patch)
treeec1306bf28af773ca70d7f0722e52d83b800385d
parent8b3425865a6952024f533af201feb23ad816aee0 (diff)
downloadlibssh-b7856780a932df08963587ab763a6ef17af90045.tar.gz
libssh-b7856780a932df08963587ab763a6ef17af90045.tar.xz
libssh-b7856780a932df08963587ab763a6ef17af90045.zip
crypto: check malloc return in ssh_mac_ctx_init
Signed-off-by: Jon Simons <jon@jonsimons.org> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> (cherry picked from commit af25c5e668fa817521496ac2278127b516f219d3)
-rw-r--r--src/libcrypto.c6
-rw-r--r--src/libgcrypt.c6
2 files changed, 10 insertions, 2 deletions
diff --git a/src/libcrypto.c b/src/libcrypto.c
index d8cc795c..174b0c64 100644
--- a/src/libcrypto.c
+++ b/src/libcrypto.c
@@ -202,7 +202,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 46179016..7590e81f 100644
--- a/src/libgcrypt.c
+++ b/src/libgcrypt.c
@@ -91,7 +91,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: