From 3710ae385f328eb3cd303e4878b357369e10c67b Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Tue, 7 Nov 2017 12:42:55 -0500 Subject: [PATCH] Return NULL if dh struct cannot be allocated completely Resolves https://bugs.launchpad.net/moonshot-tr/+bug/1730679 --- common/tr_dh.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/common/tr_dh.c b/common/tr_dh.c index 031b404..906d53c 100644 --- a/common/tr_dh.c +++ b/common/tr_dh.c @@ -82,7 +82,7 @@ DH *tr_dh_new(void) return DH_new(); } -DH *tr_create_dh_params(unsigned char *priv_key, +DH *tr_create_dh_params(unsigned char *priv_key, size_t keylen) { DH *dh = NULL; @@ -95,6 +95,7 @@ DH *tr_create_dh_params(unsigned char *priv_key, (NULL == (dh->p = BN_new())) || (NULL == (dh->q = BN_new()))) { DH_free(dh); + return NULL; } BN_set_word(dh->g, 2); @@ -235,15 +236,15 @@ DH *tr_dh_dup(DH *in) return out; } -int tr_compute_dh_key(unsigned char **pbuf, - BIGNUM *pub_key, +int tr_compute_dh_key(unsigned char **pbuf, + BIGNUM *pub_key, DH *priv_dh) { size_t buflen; unsigned char *buf = NULL;; int rc = 0; - - if ((!pbuf) || - (!pub_key) || + + if ((!pbuf) || + (!pub_key) || (!priv_dh)) { tr_debug("tr_compute_dh_key: Invalid parameters."); return(-1); @@ -256,7 +257,7 @@ int tr_compute_dh_key(unsigned char **pbuf, return -1; } - + rc = DH_compute_key(buf, pub_key, priv_dh); if (0 <= rc) { *pbuf = buf; -- 2.1.4