diff options
author | Matt Caswell <matt@openssl.org> | 2016-05-04 11:28:38 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-05-18 10:47:15 +0100 |
commit | 6ef020c988bb508842dfcd517a4b41cae214f641 (patch) | |
tree | c7cbc8c5fc0456b157c02c0a97fae580dab81b15 /crypto/dh | |
parent | 24854e0117000b81319665154c93e15743bf7de6 (diff) |
Better checks for malloc failure in various METHOD functions
A number of the METHOD functions weren't properly handling malloc failures.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/dh')
-rw-r--r-- | crypto/dh/dh_meth.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/crypto/dh/dh_meth.c b/crypto/dh/dh_meth.c index 11fd8e38d0..dbc03143fb 100644 --- a/crypto/dh/dh_meth.c +++ b/crypto/dh/dh_meth.c @@ -16,6 +16,10 @@ DH_METHOD *DH_meth_new(const char *name, int flags) if (dhm != NULL) { dhm->name = OPENSSL_strdup(name); + if (dhm->name == NULL) { + OPENSSL_free(dhm); + return NULL; + } dhm->flags = flags; } @@ -40,6 +44,10 @@ DH_METHOD *DH_meth_dup(const DH_METHOD *dhm) if (ret != NULL) { memcpy(ret, dhm, sizeof(*dhm)); ret->name = OPENSSL_strdup(dhm->name); + if (ret->name == NULL) { + OPENSSL_free(ret); + return NULL; + } } return ret; @@ -52,10 +60,16 @@ const char *DH_meth_get0_name(const DH_METHOD *dhm) int DH_meth_set1_name(DH_METHOD *dhm, const char *name) { + char *tmpname; + + tmpname = OPENSSL_strdup(name); + if (tmpname == NULL) + return 0; + OPENSSL_free(dhm->name); - dhm->name = OPENSSL_strdup(name); + dhm->name = tmpname; - return dhm->name != NULL; + return 1; } int DH_meth_get_flags(DH_METHOD *dhm) |