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>
This commit is contained in:
parent
24854e0117
commit
6ef020c988
4 changed files with 57 additions and 10 deletions
|
@ -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)
|
||||
{
|
||||
OPENSSL_free(dhm->name);
|
||||
dhm->name = OPENSSL_strdup(name);
|
||||
char *tmpname;
|
||||
|
||||
return dhm->name != NULL;
|
||||
tmpname = OPENSSL_strdup(name);
|
||||
if (tmpname == NULL)
|
||||
return 0;
|
||||
|
||||
OPENSSL_free(dhm->name);
|
||||
dhm->name = tmpname;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DH_meth_get_flags(DH_METHOD *dhm)
|
||||
|
|
|
@ -24,6 +24,10 @@ DSA_METHOD *DSA_meth_new(const char *name, int flags)
|
|||
|
||||
if (dsam != NULL) {
|
||||
dsam->name = OPENSSL_strdup(name);
|
||||
if (dsam->name == NULL) {
|
||||
OPENSSL_free(dsam);
|
||||
return NULL;
|
||||
}
|
||||
dsam->flags = flags;
|
||||
}
|
||||
|
||||
|
@ -48,6 +52,10 @@ DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam)
|
|||
if (ret != NULL) {
|
||||
memcpy(ret, dsam, sizeof(*dsam));
|
||||
ret->name = OPENSSL_strdup(dsam->name);
|
||||
if (ret->name == NULL) {
|
||||
OPENSSL_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -60,10 +68,16 @@ const char *DSA_meth_get0_name(const DSA_METHOD *dsam)
|
|||
|
||||
int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name)
|
||||
{
|
||||
OPENSSL_free(dsam->name);
|
||||
dsam->name = OPENSSL_strdup(name);
|
||||
char *tmpname;
|
||||
|
||||
return dsam->name != NULL;
|
||||
tmpname = OPENSSL_strdup(name);
|
||||
if (tmpname == NULL)
|
||||
return 0;
|
||||
|
||||
OPENSSL_free(dsam->name);
|
||||
dsam->name = tmpname;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DSA_meth_get_flags(DSA_METHOD *dsam)
|
||||
|
|
|
@ -16,6 +16,10 @@ RSA_METHOD *RSA_meth_new(const char *name, int flags)
|
|||
|
||||
if (meth != NULL) {
|
||||
meth->name = OPENSSL_strdup(name);
|
||||
if (meth->name == NULL) {
|
||||
OPENSSL_free(meth);
|
||||
return NULL;
|
||||
}
|
||||
meth->flags = flags;
|
||||
}
|
||||
|
||||
|
@ -40,6 +44,10 @@ RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth)
|
|||
if (ret != NULL) {
|
||||
memcpy(ret, meth, sizeof(*meth));
|
||||
ret->name = OPENSSL_strdup(meth->name);
|
||||
if (ret->name == NULL) {
|
||||
OPENSSL_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -52,10 +60,16 @@ const char *RSA_meth_get0_name(const RSA_METHOD *meth)
|
|||
|
||||
int RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
|
||||
{
|
||||
OPENSSL_free(meth->name);
|
||||
meth->name = OPENSSL_strdup(name);
|
||||
char *tmpname;
|
||||
|
||||
return meth->name != NULL;
|
||||
tmpname = OPENSSL_strdup(name);
|
||||
if (tmpname == NULL)
|
||||
return 0;
|
||||
|
||||
OPENSSL_free(meth->name);
|
||||
meth->name = tmpname;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int RSA_meth_get_flags(RSA_METHOD *meth)
|
||||
|
|
|
@ -536,8 +536,13 @@ UI_METHOD *UI_create_method(char *name)
|
|||
{
|
||||
UI_METHOD *ui_method = OPENSSL_zalloc(sizeof(*ui_method));
|
||||
|
||||
if (ui_method != NULL)
|
||||
if (ui_method != NULL) {
|
||||
ui_method->name = OPENSSL_strdup(name);
|
||||
if (ui_method->name == NULL) {
|
||||
OPENSSL_free(ui_method);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return ui_method;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue