From 694428926dc83282ccb4d9e48dd9f22565103267 Mon Sep 17 00:00:00 2001 From: beck Date: Tue, 22 Jul 2014 02:21:20 +0000 Subject: [PATCH] Kill a bunch more BUF_strdup's - these are converted to have a check for NULL before an intrinsic strdup. ok miod@ --- lib/libcrypto/conf/conf_mod.c | 6 ++++-- lib/libcrypto/cryptlib.c | 4 ++-- lib/libcrypto/srp/srp_vfy.c | 7 ++++--- lib/libcrypto/store/str_meth.c | 6 +++--- lib/libcrypto/ui/ui_lib.c | 6 +++--- lib/libcrypto/x509/x509_vpm.c | 6 ++++-- lib/libssl/src/crypto/conf/conf_mod.c | 6 ++++-- lib/libssl/src/crypto/cryptlib.c | 4 ++-- lib/libssl/src/crypto/srp/srp_vfy.c | 7 ++++--- lib/libssl/src/crypto/store/str_meth.c | 6 +++--- lib/libssl/src/crypto/ui/ui_lib.c | 6 +++--- lib/libssl/src/crypto/x509/x509_vpm.c | 6 ++++-- 12 files changed, 40 insertions(+), 30 deletions(-) diff --git a/lib/libcrypto/conf/conf_mod.c b/lib/libcrypto/conf/conf_mod.c index c4c429497c2..4363f297c76 100644 --- a/lib/libcrypto/conf/conf_mod.c +++ b/lib/libcrypto/conf/conf_mod.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf_mod.c,v 1.24 2014/07/13 16:03:09 beck Exp $ */ +/* $OpenBSD: conf_mod.c,v 1.25 2014/07/22 02:21:20 beck Exp $ */ /* Written by Stephen Henson (steve@openssl.org) for the OpenSSL * project 2001. */ @@ -283,6 +283,8 @@ module_add(DSO *dso, const char *name, conf_init_func *ifunc, { CONF_MODULE *tmod = NULL; + if (name == NULL) + return NULL; if (supported_modules == NULL) supported_modules = sk_CONF_MODULE_new_null(); if (supported_modules == NULL) @@ -292,7 +294,7 @@ module_add(DSO *dso, const char *name, conf_init_func *ifunc, return NULL; tmod->dso = dso; - tmod->name = BUF_strdup(name); + tmod->name = strdup(name); tmod->init = ifunc; tmod->finish = ffunc; tmod->links = 0; diff --git a/lib/libcrypto/cryptlib.c b/lib/libcrypto/cryptlib.c index 6a75d9568c0..000f76a6a23 100644 --- a/lib/libcrypto/cryptlib.c +++ b/lib/libcrypto/cryptlib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cryptlib.c,v 1.32 2014/07/11 08:44:47 jsing Exp $ */ +/* $OpenBSD: cryptlib.c,v 1.33 2014/07/22 02:21:20 beck Exp $ */ /* ==================================================================== * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. * @@ -210,7 +210,7 @@ CRYPTO_get_new_lockid(char *name) CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID, ERR_R_MALLOC_FAILURE); return (0); } - if ((str = BUF_strdup(name)) == NULL) { + if (name == NULL || (str = strdup(name)) == NULL) { CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID, ERR_R_MALLOC_FAILURE); return (0); } diff --git a/lib/libcrypto/srp/srp_vfy.c b/lib/libcrypto/srp/srp_vfy.c index 6de843527d1..0b2a3415c20 100644 --- a/lib/libcrypto/srp/srp_vfy.c +++ b/lib/libcrypto/srp/srp_vfy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: srp_vfy.c,v 1.8 2014/07/13 16:03:10 beck Exp $ */ +/* $OpenBSD: srp_vfy.c,v 1.9 2014/07/22 02:21:20 beck Exp $ */ /* Written by Christophe Renou (christophe.renou@edelweb.fr) with * the precious help of Peter Sylvester (peter.sylvester@edelweb.fr) * for the EdelKey project and contributed to the OpenSSL project 2004. @@ -291,7 +291,7 @@ static SRP_gN_cache *SRP_gN_new_init(const char *ch) if (newgN == NULL) return NULL; - if ((newgN->b64_bn = BUF_strdup(ch)) == NULL) + if (ch == NULL || (newgN->b64_bn = strdup(ch)) == NULL) goto err; len = t_fromb64(tmp, ch); @@ -402,7 +402,8 @@ int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file) if ((gN = malloc(sizeof(SRP_gN))) == NULL) goto err; - if (!(gN->id = BUF_strdup(pp[DB_srpid])) + if ( (pp[DB_srpid] == NULL) + || !(gN->id = strdup(pp[DB_srpid])) || !(gN->N = SRP_gN_place_bn(vb->gN_cache,pp[DB_srpverifier])) || !(gN->g = SRP_gN_place_bn(vb->gN_cache,pp[DB_srpsalt])) || sk_SRP_gN_insert(SRP_gN_tab,gN,0) == 0) diff --git a/lib/libcrypto/store/str_meth.c b/lib/libcrypto/store/str_meth.c index b3d4f9cc373..9d7c5ed98d8 100644 --- a/lib/libcrypto/store/str_meth.c +++ b/lib/libcrypto/store/str_meth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: str_meth.c,v 1.6 2014/06/12 15:49:30 deraadt Exp $ */ +/* $OpenBSD: str_meth.c,v 1.7 2014/07/22 02:21:20 beck Exp $ */ /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL * project 2003. */ @@ -65,8 +65,8 @@ STORE_create_method(char *name) { STORE_METHOD *store_method = calloc(1, sizeof(STORE_METHOD)); - if (store_method) - store_method->name = BUF_strdup(name); + if (store_method && name) + store_method->name = strdup(name); return store_method; } diff --git a/lib/libcrypto/ui/ui_lib.c b/lib/libcrypto/ui/ui_lib.c index 4fabcd99093..baf86d7635b 100644 --- a/lib/libcrypto/ui/ui_lib.c +++ b/lib/libcrypto/ui/ui_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ui_lib.c,v 1.27 2014/07/13 16:03:10 beck Exp $ */ +/* $OpenBSD: ui_lib.c,v 1.28 2014/07/22 02:21:20 beck Exp $ */ /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL * project 2001. */ @@ -585,8 +585,8 @@ UI_create_method(char *name) { UI_METHOD *ui_method = calloc(1, sizeof(UI_METHOD)); - if (ui_method) - ui_method->name = BUF_strdup(name); + if (ui_method && name) + ui_method->name = strdup(name); return ui_method; } diff --git a/lib/libcrypto/x509/x509_vpm.c b/lib/libcrypto/x509/x509_vpm.c index ec352672985..4ad2350222e 100644 --- a/lib/libcrypto/x509/x509_vpm.c +++ b/lib/libcrypto/x509/x509_vpm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_vpm.c,v 1.9 2014/07/11 08:44:49 jsing Exp $ */ +/* $OpenBSD: x509_vpm.c,v 1.10 2014/07/22 02:21:20 beck Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2004. */ @@ -213,7 +213,9 @@ int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name) { free(param->name); - param->name = BUF_strdup(name); + if (name == NULL) + return 1; + param->name = strdup(name); if (param->name) return 1; return 0; diff --git a/lib/libssl/src/crypto/conf/conf_mod.c b/lib/libssl/src/crypto/conf/conf_mod.c index c4c429497c2..4363f297c76 100644 --- a/lib/libssl/src/crypto/conf/conf_mod.c +++ b/lib/libssl/src/crypto/conf/conf_mod.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf_mod.c,v 1.24 2014/07/13 16:03:09 beck Exp $ */ +/* $OpenBSD: conf_mod.c,v 1.25 2014/07/22 02:21:20 beck Exp $ */ /* Written by Stephen Henson (steve@openssl.org) for the OpenSSL * project 2001. */ @@ -283,6 +283,8 @@ module_add(DSO *dso, const char *name, conf_init_func *ifunc, { CONF_MODULE *tmod = NULL; + if (name == NULL) + return NULL; if (supported_modules == NULL) supported_modules = sk_CONF_MODULE_new_null(); if (supported_modules == NULL) @@ -292,7 +294,7 @@ module_add(DSO *dso, const char *name, conf_init_func *ifunc, return NULL; tmod->dso = dso; - tmod->name = BUF_strdup(name); + tmod->name = strdup(name); tmod->init = ifunc; tmod->finish = ffunc; tmod->links = 0; diff --git a/lib/libssl/src/crypto/cryptlib.c b/lib/libssl/src/crypto/cryptlib.c index 6a75d9568c0..000f76a6a23 100644 --- a/lib/libssl/src/crypto/cryptlib.c +++ b/lib/libssl/src/crypto/cryptlib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cryptlib.c,v 1.32 2014/07/11 08:44:47 jsing Exp $ */ +/* $OpenBSD: cryptlib.c,v 1.33 2014/07/22 02:21:20 beck Exp $ */ /* ==================================================================== * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. * @@ -210,7 +210,7 @@ CRYPTO_get_new_lockid(char *name) CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID, ERR_R_MALLOC_FAILURE); return (0); } - if ((str = BUF_strdup(name)) == NULL) { + if (name == NULL || (str = strdup(name)) == NULL) { CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID, ERR_R_MALLOC_FAILURE); return (0); } diff --git a/lib/libssl/src/crypto/srp/srp_vfy.c b/lib/libssl/src/crypto/srp/srp_vfy.c index 6de843527d1..0b2a3415c20 100644 --- a/lib/libssl/src/crypto/srp/srp_vfy.c +++ b/lib/libssl/src/crypto/srp/srp_vfy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: srp_vfy.c,v 1.8 2014/07/13 16:03:10 beck Exp $ */ +/* $OpenBSD: srp_vfy.c,v 1.9 2014/07/22 02:21:20 beck Exp $ */ /* Written by Christophe Renou (christophe.renou@edelweb.fr) with * the precious help of Peter Sylvester (peter.sylvester@edelweb.fr) * for the EdelKey project and contributed to the OpenSSL project 2004. @@ -291,7 +291,7 @@ static SRP_gN_cache *SRP_gN_new_init(const char *ch) if (newgN == NULL) return NULL; - if ((newgN->b64_bn = BUF_strdup(ch)) == NULL) + if (ch == NULL || (newgN->b64_bn = strdup(ch)) == NULL) goto err; len = t_fromb64(tmp, ch); @@ -402,7 +402,8 @@ int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file) if ((gN = malloc(sizeof(SRP_gN))) == NULL) goto err; - if (!(gN->id = BUF_strdup(pp[DB_srpid])) + if ( (pp[DB_srpid] == NULL) + || !(gN->id = strdup(pp[DB_srpid])) || !(gN->N = SRP_gN_place_bn(vb->gN_cache,pp[DB_srpverifier])) || !(gN->g = SRP_gN_place_bn(vb->gN_cache,pp[DB_srpsalt])) || sk_SRP_gN_insert(SRP_gN_tab,gN,0) == 0) diff --git a/lib/libssl/src/crypto/store/str_meth.c b/lib/libssl/src/crypto/store/str_meth.c index b3d4f9cc373..9d7c5ed98d8 100644 --- a/lib/libssl/src/crypto/store/str_meth.c +++ b/lib/libssl/src/crypto/store/str_meth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: str_meth.c,v 1.6 2014/06/12 15:49:30 deraadt Exp $ */ +/* $OpenBSD: str_meth.c,v 1.7 2014/07/22 02:21:20 beck Exp $ */ /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL * project 2003. */ @@ -65,8 +65,8 @@ STORE_create_method(char *name) { STORE_METHOD *store_method = calloc(1, sizeof(STORE_METHOD)); - if (store_method) - store_method->name = BUF_strdup(name); + if (store_method && name) + store_method->name = strdup(name); return store_method; } diff --git a/lib/libssl/src/crypto/ui/ui_lib.c b/lib/libssl/src/crypto/ui/ui_lib.c index 4fabcd99093..baf86d7635b 100644 --- a/lib/libssl/src/crypto/ui/ui_lib.c +++ b/lib/libssl/src/crypto/ui/ui_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ui_lib.c,v 1.27 2014/07/13 16:03:10 beck Exp $ */ +/* $OpenBSD: ui_lib.c,v 1.28 2014/07/22 02:21:20 beck Exp $ */ /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL * project 2001. */ @@ -585,8 +585,8 @@ UI_create_method(char *name) { UI_METHOD *ui_method = calloc(1, sizeof(UI_METHOD)); - if (ui_method) - ui_method->name = BUF_strdup(name); + if (ui_method && name) + ui_method->name = strdup(name); return ui_method; } diff --git a/lib/libssl/src/crypto/x509/x509_vpm.c b/lib/libssl/src/crypto/x509/x509_vpm.c index ec352672985..4ad2350222e 100644 --- a/lib/libssl/src/crypto/x509/x509_vpm.c +++ b/lib/libssl/src/crypto/x509/x509_vpm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_vpm.c,v 1.9 2014/07/11 08:44:49 jsing Exp $ */ +/* $OpenBSD: x509_vpm.c,v 1.10 2014/07/22 02:21:20 beck Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2004. */ @@ -213,7 +213,9 @@ int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name) { free(param->name); - param->name = BUF_strdup(name); + if (name == NULL) + return 1; + param->name = strdup(name); if (param->name) return 1; return 0; -- 2.20.1