diff --git a/apps/apps.c b/apps/apps.c index c6b70d63a8..685536a434 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -432,14 +432,14 @@ static char *app_get_pass(char *arg, int keepbio) int i; if (strncmp(arg, "pass:", 5) == 0) - return BUF_strdup(arg + 5); + return OPENSSL_strdup(arg + 5); if (strncmp(arg, "env:", 4) == 0) { tmp = getenv(arg + 4); if (!tmp) { BIO_printf(bio_err, "Can't read environment variable %s\n", arg + 4); return NULL; } - return BUF_strdup(tmp); + return OPENSSL_strdup(tmp); } if (!keepbio || !pwdbio) { if (strncmp(arg, "file:", 5) == 0) { @@ -495,7 +495,7 @@ static char *app_get_pass(char *arg, int keepbio) tmp = strchr(tpass, '\n'); if (tmp) *tmp = 0; - return BUF_strdup(tpass); + return OPENSSL_strdup(tpass); } static CONF *app_load_config_(BIO *in, const char *filename) @@ -1444,7 +1444,7 @@ int save_serial(char *serialfile, char *suffix, BIGNUM *serial, } if (suffix == NULL) - BUF_strlcpy(buf[0], serialfile, BSIZE); + OPENSSL_strlcpy(buf[0], serialfile, BSIZE); else { #ifndef OPENSSL_SYS_VMS j = BIO_snprintf(buf[0], sizeof buf[0], "%s.%s", serialfile, suffix); @@ -1930,7 +1930,7 @@ int pkey_ctrl_string(EVP_PKEY_CTX *ctx, char *value) { int rv; char *stmp, *vtmp = NULL; - stmp = BUF_strdup(value); + stmp = OPENSSL_strdup(value); if (!stmp) return -1; vtmp = strchr(stmp, ':'); diff --git a/apps/ca.c b/apps/ca.c index 6404e48507..59fcea20ed 100644 --- a/apps/ca.c +++ b/apps/ca.c @@ -1067,7 +1067,7 @@ end_of_options: strcpy(buf[2], outdir); #ifndef OPENSSL_SYS_VMS - BUF_strlcat(buf[2], "/", sizeof(buf[2])); + OPENSSL_strlcat(buf[2], "/", sizeof(buf[2])); #endif n = (char *)&(buf[2][strlen(buf[2])]); @@ -1679,7 +1679,7 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, } if (BN_is_zero(serial)) - row[DB_serial] = BUF_strdup("00"); + row[DB_serial] = OPENSSL_strdup("00"); else row[DB_serial] = BN_bn2hex(serial); if (row[DB_serial] == NULL) { @@ -1898,17 +1898,13 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, goto end; /* We now just add it to the database */ - row[DB_type] = app_malloc(2, "row db type"); - + row[DB_type] = OPENSSL_strdup("V"); tm = X509_get_notAfter(ret); row[DB_exp_date] = app_malloc(tm->length + 1, "row expdate"); memcpy(row[DB_exp_date], tm->data, tm->length); row[DB_exp_date][tm->length] = '\0'; - row[DB_rev_date] = NULL; - - /* row[DB_serial] done already */ - row[DB_file] = app_malloc(8, "row file"); + row[DB_file] = OPENSSL_strdup("unknown"); row[DB_name] = X509_NAME_oneline(X509_get_subject_name(ret), NULL, 0); if ((row[DB_type] == NULL) || (row[DB_exp_date] == NULL) || @@ -1916,9 +1912,6 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, BIO_printf(bio_err, "Memory allocation failure\n"); goto end; } - BUF_strlcpy(row[DB_file], "unknown", 8); - row[DB_type][0] = 'V'; - row[DB_type][1] = '\0'; irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row space"); for (i = 0; i < DB_NUMBER; i++) { @@ -2118,7 +2111,7 @@ static int do_revoke(X509 *x509, CA_DB *db, int type, char *value) if (!bn) goto end; if (BN_is_zero(bn)) - row[DB_serial] = BUF_strdup("00"); + row[DB_serial] = OPENSSL_strdup("00"); else row[DB_serial] = BN_bn2hex(bn); BN_free(bn); @@ -2137,23 +2130,13 @@ static int do_revoke(X509 *x509, CA_DB *db, int type, char *value) row[DB_serial], row[DB_name]); /* We now just add it to the database */ - row[DB_type] = app_malloc(2, "row type"); - + row[DB_type] = OPENSSL_strdup("V"); tm = X509_get_notAfter(x509); row[DB_exp_date] = app_malloc(tm->length + 1, "row exp_data"); memcpy(row[DB_exp_date], tm->data, tm->length); row[DB_exp_date][tm->length] = '\0'; - row[DB_rev_date] = NULL; - - /* row[DB_serial] done already */ - row[DB_file] = app_malloc(8, "row filename"); - - /* row[DB_name] done already */ - - BUF_strlcpy(row[DB_file], "unknown", 8); - row[DB_type][0] = 'V'; - row[DB_type][1] = '\0'; + row[DB_file] = OPENSSL_strdup("unknown"); irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row ptr"); for (i = 0; i < DB_NUMBER; i++) { @@ -2428,14 +2411,14 @@ char *make_revocation_str(int rev_type, char *rev_arg) i += strlen(other) + 1; str = app_malloc(i, "revocation reason"); - BUF_strlcpy(str, (char *)revtm->data, i); + OPENSSL_strlcpy(str, (char *)revtm->data, i); if (reason) { - BUF_strlcat(str, ",", i); - BUF_strlcat(str, reason, i); + OPENSSL_strlcat(str, ",", i); + OPENSSL_strlcat(str, reason, i); } if (other) { - BUF_strlcat(str, ",", i); - BUF_strlcat(str, other, i); + OPENSSL_strlcat(str, ",", i); + OPENSSL_strlcat(str, other, i); } ASN1_UTCTIME_free(revtm); return str; @@ -2553,7 +2536,7 @@ int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold, ASN1_OBJECT *hold = NULL; ASN1_GENERALIZEDTIME *comp_time = NULL; - tmp = BUF_strdup(str); + tmp = OPENSSL_strdup(str); if (!tmp) { BIO_printf(bio_err, "memory allocation failure\n"); goto end; diff --git a/apps/cms.c b/apps/cms.c index 14f8f55f2b..8cf99de516 100644 --- a/apps/cms.c +++ b/apps/cms.c @@ -902,7 +902,7 @@ int cms_main(int argc, char **argv) secret_keyid = NULL; } if (pwri_pass) { - pwri_tmp = (unsigned char *)BUF_strdup((char *)pwri_pass); + pwri_tmp = (unsigned char *)OPENSSL_strdup((char *)pwri_pass); if (!pwri_tmp) goto end; if (!CMS_add0_recipient_password(cms, diff --git a/apps/engine.c b/apps/engine.c index 17e6f789f7..c373df579c 100644 --- a/apps/engine.c +++ b/apps/engine.c @@ -109,8 +109,8 @@ static int append_buf(char **buf, const char *s, int *size, int step) return 0; if (**buf != '\0') - BUF_strlcat(*buf, ", ", *size); - BUF_strlcat(*buf, s, *size); + OPENSSL_strlcat(*buf, ", ", *size); + OPENSSL_strlcat(*buf, s, *size); return 1; } diff --git a/apps/ocsp.c b/apps/ocsp.c index ef7d62acd1..ceda592de9 100644 --- a/apps/ocsp.c +++ b/apps/ocsp.c @@ -1007,7 +1007,7 @@ static char **lookup_serial(CA_DB *db, ASN1_INTEGER *ser) OPENSSL_assert(bn); /* FIXME: should report an error at this * point and abort */ if (BN_is_zero(bn)) - itmp = BUF_strdup("00"); + itmp = OPENSSL_strdup("00"); else itmp = BN_bn2hex(bn); row[DB_serial] = itmp; diff --git a/apps/openssl.c b/apps/openssl.c index 592095e5f9..5ce04ceaf3 100644 --- a/apps/openssl.c +++ b/apps/openssl.c @@ -218,7 +218,7 @@ static char *make_config_name() char *p; if ((t = getenv("OPENSSL_CONF")) != NULL) - return BUF_strdup(t); + return OPENSSL_strdup(t); t = X509_get_default_cert_area(); len = strlen(t) + 1 + strlen(OPENSSL_CONF) + 1; diff --git a/apps/passwd.c b/apps/passwd.c index 2a32111e9d..f0ab243580 100644 --- a/apps/passwd.c +++ b/apps/passwd.c @@ -314,9 +314,9 @@ static char *md5crypt(const char *passwd, const char *magic, const char *salt) out_buf[0] = '$'; out_buf[1] = 0; assert(strlen(magic) <= 4); /* "1" or "apr1" */ - strncat(out_buf, magic, 4); - strncat(out_buf, "$", 1); - strncat(out_buf, salt, 8); + OPENSSL_strlcat(out_buf, magic, sizeof out_buf); + OPENSSL_strlcat(out_buf, "$", sizeof out_buf); + OPENSSL_strlcat(out_buf, salt, sizeof out_buf); assert(strlen(out_buf) <= 6 + 8); /* "$apr1$..salt.." */ salt_out = out_buf + 2 + strlen(magic); salt_len = strlen(salt_out); diff --git a/apps/pkcs12.c b/apps/pkcs12.c index 11930e9e16..3d566f3df2 100644 --- a/apps/pkcs12.c +++ b/apps/pkcs12.c @@ -484,7 +484,7 @@ int pkcs12_main(int argc, char **argv) goto export_end; } if (!twopass) - BUF_strlcpy(macpass, pass, sizeof macpass); + OPENSSL_strlcpy(macpass, pass, sizeof macpass); p12 = PKCS12_create(cpass, name, key, ucert, certs, key_pbe, cert_pbe, iter, -1, keytype); @@ -542,7 +542,7 @@ int pkcs12_main(int argc, char **argv) } if (!twopass) - BUF_strlcpy(macpass, pass, sizeof macpass); + OPENSSL_strlcpy(macpass, pass, sizeof macpass); if ((options & INFO) && p12->mac) BIO_printf(bio_err, "MAC Iteration %ld\n", diff --git a/apps/rehash.c b/apps/rehash.c index e85265d1e6..38084a247f 100644 --- a/apps/rehash.c +++ b/apps/rehash.c @@ -175,7 +175,7 @@ static int add_entry(enum Type type, unsigned int hash, const char *filename, ep = app_malloc(sizeof(*ep), "collision bucket"); *ep = nilhentry; ep->old_id = ~0; - ep->filename = BUF_strdup(filename); + ep->filename = OPENSSL_strdup(filename); if (bp->last_entry) bp->last_entry->next = ep; if (bp->first_entry == NULL) @@ -468,7 +468,7 @@ int rehash_main(int argc, char **argv) while (*argv) errs += do_dir(*argv++, h); } else if ((env = getenv("SSL_CERT_DIR")) != NULL) { - m = BUF_strdup(env); + m = OPENSSL_strdup(env); for (e = strtok(m, ":"); e != NULL; e = strtok(NULL, ":")) errs += do_dir(e, h); OPENSSL_free(m); diff --git a/apps/req.c b/apps/req.c index c275763932..a0da788089 100644 --- a/apps/req.c +++ b/apps/req.c @@ -1189,8 +1189,8 @@ static int add_DN_object(X509_NAME *n, char *text, const char *def, BIO_printf(bio_err, "%s [%s]:", text, def); (void)BIO_flush(bio_err); if (value != NULL) { - BUF_strlcpy(buf, value, sizeof buf); - BUF_strlcat(buf, "\n", sizeof buf); + OPENSSL_strlcpy(buf, value, sizeof buf); + OPENSSL_strlcat(buf, "\n", sizeof buf); BIO_printf(bio_err, "%s\n", value); } else { buf[0] = '\0'; @@ -1208,8 +1208,8 @@ static int add_DN_object(X509_NAME *n, char *text, const char *def, else if (buf[0] == '\n') { if ((def == NULL) || (def[0] == '\0')) return (1); - BUF_strlcpy(buf, def, sizeof buf); - BUF_strlcat(buf, "\n", sizeof buf); + OPENSSL_strlcpy(buf, def, sizeof buf); + OPENSSL_strlcat(buf, "\n", sizeof buf); } else if ((buf[0] == '.') && (buf[1] == '\n')) return (1); @@ -1248,8 +1248,8 @@ static int add_attribute_object(X509_REQ *req, char *text, const char *def, BIO_printf(bio_err, "%s [%s]:", text, def); (void)BIO_flush(bio_err); if (value != NULL) { - BUF_strlcpy(buf, value, sizeof buf); - BUF_strlcat(buf, "\n", sizeof buf); + OPENSSL_strlcpy(buf, value, sizeof buf); + OPENSSL_strlcat(buf, "\n", sizeof buf); BIO_printf(bio_err, "%s\n", value); } else { buf[0] = '\0'; @@ -1267,8 +1267,8 @@ static int add_attribute_object(X509_REQ *req, char *text, const char *def, else if (buf[0] == '\n') { if ((def == NULL) || (def[0] == '\0')) return (1); - BUF_strlcpy(buf, def, sizeof buf); - BUF_strlcat(buf, "\n", sizeof buf); + OPENSSL_strlcpy(buf, def, sizeof buf); + OPENSSL_strlcat(buf, "\n", sizeof buf); } else if ((buf[0] == '.') && (buf[1] == '\n')) return (1); @@ -1428,7 +1428,7 @@ static EVP_PKEY_CTX *set_keygen_ctx(const char *gstr, return NULL; } EVP_PKEY_asn1_get0_info(NULL, NULL, NULL, NULL, &anam, ameth); - *palgnam = BUF_strdup(anam); + *palgnam = OPENSSL_strdup(anam); #ifndef OPENSSL_NO_ENGINE if (tmpeng) ENGINE_finish(tmpeng); diff --git a/apps/s_server.c b/apps/s_server.c index 698dd1c73b..84a640ef1a 100644 --- a/apps/s_server.c +++ b/apps/s_server.c @@ -3165,7 +3165,7 @@ static int add_session(SSL *ssl, SSL_SESSION *session) return 0; } - sess->id = BUF_memdup(SSL_SESSION_get_id(session, NULL), sess->idlen); + sess->id = OPENSSL_memdup(SSL_SESSION_get_id(session, NULL), sess->idlen); sess->der = app_malloc(sess->derlen, "get session buffer"); if (!sess->id) { BIO_printf(bio_err, "Out of memory adding to external cache\n"); diff --git a/apps/s_socket.c b/apps/s_socket.c index 9d1f04a6c5..75053e9591 100644 --- a/apps/s_socket.c +++ b/apps/s_socket.c @@ -560,7 +560,7 @@ static int do_accept(int acc_sock, int *sock, char **host) /* return(0); */ } else { *host = app_malloc(strlen(h1->h_name) + 1, "copy hostname"); - BUF_strlcpy(*host, h1->h_name, strlen(h1->h_name) + 1); + OPENSSL_strlcpy(*host, h1->h_name, strlen(h1->h_name) + 1); h2 = gethostbyname(*host); if (h2 == NULL) { diff --git a/apps/srp.c b/apps/srp.c index 24fb79887e..1c9a9bee43 100644 --- a/apps/srp.c +++ b/apps/srp.c @@ -486,9 +486,9 @@ int srp_main(int argc, char **argv) errors++; goto end; } - row[DB_srpid] = BUF_strdup(user); - row[DB_srptype] = BUF_strdup("v"); - row[DB_srpgN] = BUF_strdup(gNid); + row[DB_srpid] = OPENSSL_strdup(user); + row[DB_srptype] = OPENSSL_strdup("v"); + row[DB_srpgN] = OPENSSL_strdup(gNid); if ((row[DB_srpid] == NULL) || (row[DB_srpgN] == NULL) @@ -496,7 +496,7 @@ int srp_main(int argc, char **argv) || (row[DB_srpverifier] == NULL) || (row[DB_srpsalt] == NULL) || (userinfo - && ((row[DB_srpinfo] = BUF_strdup(userinfo)) == NULL)) + && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo)) == NULL)) || !update_index(db, row)) { OPENSSL_free(row[DB_srpid]); OPENSSL_free(row[DB_srpgN]); @@ -571,7 +571,7 @@ int srp_main(int argc, char **argv) } row[DB_srptype][0] = 'v'; - row[DB_srpgN] = BUF_strdup(gNid); + row[DB_srpgN] = OPENSSL_strdup(gNid); if (row[DB_srpid] == NULL || row[DB_srpgN] == NULL @@ -579,7 +579,7 @@ int srp_main(int argc, char **argv) || row[DB_srpverifier] == NULL || row[DB_srpsalt] == NULL || (userinfo - && ((row[DB_srpinfo] = BUF_strdup(userinfo)) + && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo)) == NULL))) goto end; diff --git a/apps/x509.c b/apps/x509.c index 1677ba5fda..283d0552af 100644 --- a/apps/x509.c +++ b/apps/x509.c @@ -949,15 +949,15 @@ static ASN1_INTEGER *x509_load_serial(char *CAfile, char *serialfile, : (strlen(serialfile))) + 1; buf = app_malloc(len, "serial# buffer"); if (serialfile == NULL) { - BUF_strlcpy(buf, CAfile, len); + OPENSSL_strlcpy(buf, CAfile, len); for (p = buf; *p; p++) if (*p == '.') { *p = '\0'; break; } - BUF_strlcat(buf, POSTFIX, len); + OPENSSL_strlcat(buf, POSTFIX, len); } else - BUF_strlcpy(buf, serialfile, len); + OPENSSL_strlcpy(buf, serialfile, len); serial = load_serial(buf, create, NULL); if (serial == NULL) diff --git a/crypto/Makefile b/crypto/Makefile index b2cf528a91..43cb71f008 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -202,8 +202,13 @@ o_init.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h o_init.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h o_init.o: ../include/openssl/safestack.h ../include/openssl/stack.h o_init.o: ../include/openssl/symhacks.h o_init.c -o_str.o: ../e_os.h ../include/internal/o_str.h ../include/openssl/e_os2.h -o_str.o: ../include/openssl/opensslconf.h o_str.c +o_str.o: ../e_os.h ../include/internal/o_str.h ../include/openssl/bio.h +o_str.o: ../include/openssl/buffer.h ../include/openssl/crypto.h +o_str.o: ../include/openssl/e_os2.h ../include/openssl/err.h +o_str.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h +o_str.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h +o_str.o: ../include/openssl/safestack.h ../include/openssl/stack.h +o_str.o: ../include/openssl/symhacks.h include/internal/cryptlib.h o_str.c o_time.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h o_time.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h o_time.o: ../include/openssl/ossl_typ.h ../include/openssl/safestack.h diff --git a/crypto/asn1/a_time.c b/crypto/asn1/a_time.c index ff82beb3ee..c5e632e356 100644 --- a/crypto/asn1/a_time.c +++ b/crypto/asn1/a_time.c @@ -139,11 +139,11 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, str = (char *)ret->data; /* Work out the century and prepend */ if (t->data[0] >= '5') - BUF_strlcpy(str, "19", newlen); + OPENSSL_strlcpy(str, "19", newlen); else - BUF_strlcpy(str, "20", newlen); + OPENSSL_strlcpy(str, "20", newlen); - BUF_strlcat(str, (char *)t->data, newlen); + OPENSSL_strlcat(str, (char *)t->data, newlen); return ret; } diff --git a/crypto/asn1/ameth_lib.c b/crypto/asn1/ameth_lib.c index 05f0a80da8..85115bc5b7 100644 --- a/crypto/asn1/ameth_lib.c +++ b/crypto/asn1/ameth_lib.c @@ -285,13 +285,13 @@ EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags, ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC; if (info) { - ameth->info = BUF_strdup(info); + ameth->info = OPENSSL_strdup(info); if (!ameth->info) goto err; } if (pem_str) { - ameth->pem_str = BUF_strdup(pem_str); + ameth->pem_str = OPENSSL_strdup(pem_str); if (!ameth->pem_str) goto err; } diff --git a/crypto/asn1/asn_mime.c b/crypto/asn1/asn_mime.c index 53690999b4..ed9d8d68b7 100644 --- a/crypto/asn1/asn_mime.c +++ b/crypto/asn1/asn_mime.c @@ -829,7 +829,7 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value) int c; if (name) { - if ((tmpname = BUF_strdup(name)) == NULL) + if ((tmpname = OPENSSL_strdup(name)) == NULL) return NULL; for (p = tmpname; *p; p++) { c = (unsigned char)*p; @@ -840,7 +840,7 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value) } } if (value) { - if ((tmpval = BUF_strdup(value)) == NULL) + if ((tmpval = OPENSSL_strdup(value)) == NULL) goto err; for (p = tmpval; *p; p++) { c = (unsigned char)*p; @@ -872,7 +872,7 @@ static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value) int c; MIME_PARAM *mparam = NULL; if (name) { - tmpname = BUF_strdup(name); + tmpname = OPENSSL_strdup(name); if (!tmpname) goto err; for (p = tmpname; *p; p++) { @@ -884,7 +884,7 @@ static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value) } } if (value) { - tmpval = BUF_strdup(value); + tmpval = OPENSSL_strdup(value); if (!tmpval) goto err; } diff --git a/crypto/bio/b_dump.c b/crypto/bio/b_dump.c index 55792b9e30..3d005e3ff9 100644 --- a/crypto/bio/b_dump.c +++ b/crypto/bio/b_dump.c @@ -104,20 +104,20 @@ int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u), if ((rows * dump_width) < len) rows++; for (i = 0; i < rows; i++) { - BUF_strlcpy(buf, str, sizeof buf); + OPENSSL_strlcpy(buf, str, sizeof buf); BIO_snprintf(tmp, sizeof tmp, "%04x - ", i * dump_width); - BUF_strlcat(buf, tmp, sizeof buf); + OPENSSL_strlcat(buf, tmp, sizeof buf); for (j = 0; j < dump_width; j++) { if (((i * dump_width) + j) >= len) { - BUF_strlcat(buf, " ", sizeof buf); + OPENSSL_strlcat(buf, " ", sizeof buf); } else { ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff; BIO_snprintf(tmp, sizeof tmp, "%02x%c", ch, j == 7 ? '-' : ' '); - BUF_strlcat(buf, tmp, sizeof buf); + OPENSSL_strlcat(buf, tmp, sizeof buf); } } - BUF_strlcat(buf, " ", sizeof buf); + OPENSSL_strlcat(buf, " ", sizeof buf); for (j = 0; j < dump_width; j++) { if (((i * dump_width) + j) >= len) break; @@ -131,9 +131,9 @@ int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u), ? os_toebcdic[ch] : '.'); #endif - BUF_strlcat(buf, tmp, sizeof buf); + OPENSSL_strlcat(buf, tmp, sizeof buf); } - BUF_strlcat(buf, "\n", sizeof buf); + OPENSSL_strlcat(buf, "\n", sizeof buf); /* * if this is the last call then update the ddt_dump thing so that we * will move the selection point in the debug window diff --git a/crypto/bio/b_sock.c b/crypto/bio/b_sock.c index e536eda2a6..cc090724e8 100644 --- a/crypto/bio/b_sock.c +++ b/crypto/bio/b_sock.c @@ -402,7 +402,7 @@ int BIO_get_accept_socket(char *host, int bind_mode) if (BIO_sock_init() != 1) return ((int)INVALID_SOCKET); - if ((str = BUF_strdup(host)) == NULL) + if ((str = OPENSSL_strdup(host)) == NULL) return ((int)INVALID_SOCKET); h = p = NULL; diff --git a/crypto/bio/bss_acpt.c b/crypto/bio/bss_acpt.c index c549c87c3c..f65ee1a6ef 100644 --- a/crypto/bio/bss_acpt.c +++ b/crypto/bio/bss_acpt.c @@ -350,7 +350,7 @@ static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr) if (num == 0) { b->init = 1; OPENSSL_free(data->param_addr); - data->param_addr = BUF_strdup(ptr); + data->param_addr = OPENSSL_strdup(ptr); } else if (num == 1) { data->accept_nbio = (ptr != NULL); } else if (num == 2) { diff --git a/crypto/bio/bss_conn.c b/crypto/bio/bss_conn.c index ba009aa6b0..929656c882 100644 --- a/crypto/bio/bss_conn.c +++ b/crypto/bio/bss_conn.c @@ -149,7 +149,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c) break; } OPENSSL_free(c->param_port); - c->param_port = BUF_strdup(p); + c->param_port = OPENSSL_strdup(p); } } @@ -455,10 +455,10 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr) b->init = 1; if (num == 0) { OPENSSL_free(data->param_hostname); - data->param_hostname = BUF_strdup(ptr); + data->param_hostname = OPENSSL_strdup(ptr); } else if (num == 1) { OPENSSL_free(data->param_port); - data->param_port = BUF_strdup(ptr); + data->param_port = OPENSSL_strdup(ptr); } else if (num == 2) { char buf[16]; unsigned char *p = ptr; @@ -466,14 +466,14 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr) BIO_snprintf(buf, sizeof buf, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); OPENSSL_free(data->param_hostname); - data->param_hostname = BUF_strdup(buf); + data->param_hostname = OPENSSL_strdup(buf); memcpy(&(data->ip[0]), ptr, 4); } else if (num == 3) { char buf[DECIMAL_SIZE(int) + 1]; BIO_snprintf(buf, sizeof buf, "%d", *(int *)ptr); OPENSSL_free(data->param_port); - data->param_port = BUF_strdup(buf); + data->param_port = OPENSSL_strdup(buf); data->port = *(int *)ptr; } } diff --git a/crypto/bio/bss_file.c b/crypto/bio/bss_file.c index 7692ee293c..c09a9a95f6 100644 --- a/crypto/bio/bss_file.c +++ b/crypto/bio/bss_file.c @@ -367,15 +367,15 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) b->shutdown = (int)num & BIO_CLOSE; if (num & BIO_FP_APPEND) { if (num & BIO_FP_READ) - BUF_strlcpy(p, "a+", sizeof p); + OPENSSL_strlcpy(p, "a+", sizeof p); else - BUF_strlcpy(p, "a", sizeof p); + OPENSSL_strlcpy(p, "a", sizeof p); } else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) - BUF_strlcpy(p, "r+", sizeof p); + OPENSSL_strlcpy(p, "r+", sizeof p); else if (num & BIO_FP_WRITE) - BUF_strlcpy(p, "w", sizeof p); + OPENSSL_strlcpy(p, "w", sizeof p); else if (num & BIO_FP_READ) - BUF_strlcpy(p, "r", sizeof p); + OPENSSL_strlcpy(p, "r", sizeof p); else { BIOerr(BIO_F_FILE_CTRL, BIO_R_BAD_FOPEN_MODE); ret = 0; diff --git a/crypto/buffer/Makefile b/crypto/buffer/Makefile index f9d52febb5..e0b6ffd324 100644 --- a/crypto/buffer/Makefile +++ b/crypto/buffer/Makefile @@ -15,8 +15,8 @@ CFLAGS= $(INCLUDES) $(CFLAG) GENERAL=Makefile LIB=$(TOP)/libcrypto.a -LIBSRC= buffer.c buf_str.c buf_err.c -LIBOBJ= buffer.o buf_str.o buf_err.o +LIBSRC= buffer.c buf_err.c +LIBOBJ= buffer.o buf_err.o SRC= $(LIBSRC) @@ -67,14 +67,6 @@ buf_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h buf_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h buf_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h buf_err.o: buf_err.c -buf_str.o: ../../e_os.h ../../include/openssl/bio.h -buf_str.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h -buf_str.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h -buf_str.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h -buf_str.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h -buf_str.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h -buf_str.o: ../../include/openssl/symhacks.h ../include/internal/cryptlib.h -buf_str.o: buf_str.c buffer.o: ../../e_os.h ../../include/openssl/bio.h buffer.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h buffer.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h diff --git a/crypto/buffer/buf_err.c b/crypto/buffer/buf_err.c index 34671aa8ba..e126edd6f1 100644 --- a/crypto/buffer/buf_err.c +++ b/crypto/buffer/buf_err.c @@ -70,12 +70,9 @@ # define ERR_REASON(reason) ERR_PACK(ERR_LIB_BUF,0,reason) static ERR_STRING_DATA BUF_str_functs[] = { - {ERR_FUNC(BUF_F_BUF_MEMDUP), "BUF_memdup"}, {ERR_FUNC(BUF_F_BUF_MEM_GROW), "BUF_MEM_grow"}, {ERR_FUNC(BUF_F_BUF_MEM_GROW_CLEAN), "BUF_MEM_grow_clean"}, {ERR_FUNC(BUF_F_BUF_MEM_NEW), "BUF_MEM_new"}, - {ERR_FUNC(BUF_F_BUF_STRDUP), "BUF_strdup"}, - {ERR_FUNC(BUF_F_BUF_STRNDUP), "BUF_strndup"}, {0, NULL} }; diff --git a/crypto/buffer/buf_str.c b/crypto/buffer/buf_str.c deleted file mode 100644 index 1f3e8a4e79..0000000000 --- a/crypto/buffer/buf_str.c +++ /dev/null @@ -1,137 +0,0 @@ -/* crypto/buffer/buffer.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include -#include "internal/cryptlib.h" -#include - -size_t BUF_strnlen(const char *str, size_t maxlen) -{ - const char *p; - - for (p = str; maxlen-- != 0 && *p != '\0'; ++p) ; - - return p - str; -} - -char *BUF_strdup(const char *str) -{ - if (str == NULL) - return NULL; - return BUF_strndup(str, strlen(str)); -} - -char *BUF_strndup(const char *str, size_t siz) -{ - char *ret; - - if (str == NULL) - return NULL; - - siz = BUF_strnlen(str, siz); - - if (siz >= INT_MAX) - return NULL; - - ret = OPENSSL_malloc(siz + 1); - if (ret == NULL) { - BUFerr(BUF_F_BUF_STRNDUP, ERR_R_MALLOC_FAILURE); - return NULL; - } - - memcpy(ret, str, siz); - ret[siz] = '\0'; - - return (ret); -} - -void *BUF_memdup(const void *data, size_t siz) -{ - void *ret; - - if (data == NULL || siz >= INT_MAX) - return NULL; - - ret = OPENSSL_malloc(siz); - if (ret == NULL) { - BUFerr(BUF_F_BUF_MEMDUP, ERR_R_MALLOC_FAILURE); - return NULL; - } - return memcpy(ret, data, siz); -} - -size_t BUF_strlcpy(char *dst, const char *src, size_t size) -{ - size_t l = 0; - for (; size > 1 && *src; size--) { - *dst++ = *src++; - l++; - } - if (size) - *dst = '\0'; - return l + strlen(src); -} - -size_t BUF_strlcat(char *dst, const char *src, size_t size) -{ - size_t l = 0; - for (; size > 0 && *dst; size--, dst++) - l++; - return l + BUF_strlcpy(dst, src, size); -} diff --git a/crypto/conf/conf_def.c b/crypto/conf/conf_def.c index 1ff49aa281..ac074056d1 100644 --- a/crypto/conf/conf_def.c +++ b/crypto/conf/conf_def.c @@ -223,7 +223,7 @@ static int def_load_bio(CONF *conf, BIO *in, long *line) goto err; } - section = BUF_strdup("default"); + section = OPENSSL_strdup("default"); if (section == NULL) { CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE); goto err; @@ -366,7 +366,7 @@ static int def_load_bio(CONF *conf, BIO *in, long *line) CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE); goto err; } - BUF_strlcpy(v->name, pname, strlen(pname) + 1); + OPENSSL_strlcpy(v->name, pname, strlen(pname) + 1); if (!str_copy(conf, psection, &(v->value), start)) goto err; diff --git a/crypto/conf/conf_mod.c b/crypto/conf/conf_mod.c index c1fbb601d5..4fafdeddd3 100644 --- a/crypto/conf/conf_mod.c +++ b/crypto/conf/conf_mod.c @@ -286,7 +286,7 @@ static CONF_MODULE *module_add(DSO *dso, const char *name, return NULL; tmod->dso = dso; - tmod->name = BUF_strdup(name); + tmod->name = OPENSSL_strdup(name); tmod->init = ifunc; tmod->finish = ffunc; @@ -340,8 +340,8 @@ static int module_init(CONF_MODULE *pmod, char *name, char *value, goto err; imod->pmod = pmod; - imod->name = BUF_strdup(name); - imod->value = BUF_strdup(value); + imod->name = OPENSSL_strdup(name); + imod->value = OPENSSL_strdup(value); imod->usr_data = NULL; if (!imod->name || !imod->value) @@ -525,7 +525,7 @@ char *CONF_get1_default_config_file(void) file = getenv("OPENSSL_CONF"); if (file) - return BUF_strdup(file); + return OPENSSL_strdup(file); len = strlen(X509_get_default_cert_area()); #ifndef OPENSSL_SYS_VMS @@ -537,11 +537,11 @@ char *CONF_get1_default_config_file(void) if (file == NULL) return NULL; - BUF_strlcpy(file, X509_get_default_cert_area(), len + 1); + OPENSSL_strlcpy(file, X509_get_default_cert_area(), len + 1); #ifndef OPENSSL_SYS_VMS - BUF_strlcat(file, "/", len + 1); + OPENSSL_strlcat(file, "/", len + 1); #endif - BUF_strlcat(file, OPENSSL_CONF, len + 1); + OPENSSL_strlcat(file, OPENSSL_CONF, len + 1); return file; } diff --git a/crypto/cpt_err.c b/crypto/cpt_err.c index b8d3fa4d7e..af505ac5b1 100644 --- a/crypto/cpt_err.c +++ b/crypto/cpt_err.c @@ -75,6 +75,7 @@ static ERR_STRING_DATA CRYPTO_str_functs[] = { {ERR_FUNC(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX), "CRYPTO_get_ex_new_index"}, {ERR_FUNC(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID), "CRYPTO_get_new_dynlockid"}, {ERR_FUNC(CRYPTO_F_CRYPTO_GET_NEW_LOCKID), "CRYPTO_get_new_lockid"}, + {ERR_FUNC(CRYPTO_F_CRYPTO_MEMDUP), "CRYPTO_memdup"}, {ERR_FUNC(CRYPTO_F_CRYPTO_NEW_EX_DATA), "CRYPTO_new_ex_data"}, {ERR_FUNC(CRYPTO_F_CRYPTO_SET_EX_DATA), "CRYPTO_set_ex_data"}, {ERR_FUNC(CRYPTO_F_DEF_ADD_INDEX), "DEF_ADD_INDEX"}, diff --git a/crypto/dh/dh_ameth.c b/crypto/dh/dh_ameth.c index 7a3d9235cf..64eaf4ca0a 100644 --- a/crypto/dh/dh_ameth.c +++ b/crypto/dh/dh_ameth.c @@ -482,7 +482,7 @@ static int int_dh_param_copy(DH *to, const DH *from, int is_x942) to->seed = NULL; to->seedlen = 0; if (from->seed) { - to->seed = BUF_memdup(from->seed, from->seedlen); + to->seed = OPENSSL_memdup(from->seed, from->seedlen); if (!to->seed) return 0; to->seedlen = from->seedlen; @@ -770,7 +770,7 @@ static int dh_cms_set_shared_info(EVP_PKEY_CTX *pctx, CMS_RecipientInfo *ri) if (ukm) { dukmlen = ASN1_STRING_length(ukm); - dukm = BUF_memdup(ASN1_STRING_data(ukm), dukmlen); + dukm = OPENSSL_memdup(ASN1_STRING_data(ukm), dukmlen); if (!dukm) goto err; } @@ -914,7 +914,7 @@ static int dh_cms_encrypt(CMS_RecipientInfo *ri) if (ukm) { dukmlen = ASN1_STRING_length(ukm); - dukm = BUF_memdup(ASN1_STRING_data(ukm), dukmlen); + dukm = OPENSSL_memdup(ASN1_STRING_data(ukm), dukmlen); if (!dukm) goto err; } diff --git a/crypto/dh/dh_pmeth.c b/crypto/dh/dh_pmeth.c index 1e12c3e9a7..a760ff5390 100644 --- a/crypto/dh/dh_pmeth.c +++ b/crypto/dh/dh_pmeth.c @@ -134,7 +134,7 @@ static int pkey_dh_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) return 0; dctx->kdf_md = sctx->kdf_md; if (dctx->kdf_ukm) { - dctx->kdf_ukm = BUF_memdup(sctx->kdf_ukm, sctx->kdf_ukmlen); + dctx->kdf_ukm = OPENSSL_memdup(sctx->kdf_ukm, sctx->kdf_ukmlen); dctx->kdf_ukmlen = sctx->kdf_ukmlen; } dctx->kdf_outlen = sctx->kdf_outlen; diff --git a/crypto/dso/dso_lib.c b/crypto/dso/dso_lib.c index 17d1732dfc..56e765721c 100644 --- a/crypto/dso/dso_lib.c +++ b/crypto/dso/dso_lib.c @@ -353,7 +353,7 @@ int DSO_set_filename(DSO *dso, const char *filename) DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_MALLOC_FAILURE); return (0); } - BUF_strlcpy(copied, filename, strlen(filename) + 1); + OPENSSL_strlcpy(copied, filename, strlen(filename) + 1); OPENSSL_free(dso->filename); dso->filename = copied; return (1); @@ -402,7 +402,7 @@ char *DSO_convert_filename(DSO *dso, const char *filename) DSOerr(DSO_F_DSO_CONVERT_FILENAME, ERR_R_MALLOC_FAILURE); return (NULL); } - BUF_strlcpy(result, filename, strlen(filename) + 1); + OPENSSL_strlcpy(result, filename, strlen(filename) + 1); } return (result); } diff --git a/crypto/ec/ec_pmeth.c b/crypto/ec/ec_pmeth.c index cbdf4e20db..bcb5063853 100644 --- a/crypto/ec/ec_pmeth.c +++ b/crypto/ec/ec_pmeth.c @@ -124,7 +124,7 @@ static int pkey_ec_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) dctx->kdf_md = sctx->kdf_md; dctx->kdf_outlen = sctx->kdf_outlen; if (sctx->kdf_ukm) { - dctx->kdf_ukm = BUF_memdup(sctx->kdf_ukm, sctx->kdf_ukmlen); + dctx->kdf_ukm = OPENSSL_memdup(sctx->kdf_ukm, sctx->kdf_ukmlen); if (!dctx->kdf_ukm) return 0; } else diff --git a/crypto/engine/eng_dyn.c b/crypto/engine/eng_dyn.c index aed50f6474..23f01cfc35 100644 --- a/crypto/engine/eng_dyn.c +++ b/crypto/engine/eng_dyn.c @@ -352,7 +352,7 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) p = NULL; OPENSSL_free(ctx->DYNAMIC_LIBNAME); if (p) - ctx->DYNAMIC_LIBNAME = BUF_strdup(p); + ctx->DYNAMIC_LIBNAME = OPENSSL_strdup(p); else ctx->DYNAMIC_LIBNAME = NULL; return (ctx->DYNAMIC_LIBNAME ? 1 : 0); @@ -365,7 +365,7 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) p = NULL; OPENSSL_free(ctx->engine_id); if (p) - ctx->engine_id = BUF_strdup(p); + ctx->engine_id = OPENSSL_strdup(p); else ctx->engine_id = NULL; return (ctx->engine_id ? 1 : 0); @@ -392,7 +392,7 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) return 0; } { - char *tmp_str = BUF_strdup(p); + char *tmp_str = OPENSSL_strdup(p); if (!tmp_str) { ENGINEerr(ENGINE_F_DYNAMIC_CTRL, ERR_R_MALLOC_FAILURE); return 0; diff --git a/crypto/err/err.c b/crypto/err/err.c index b7ca3ded05..236f8ac546 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -968,7 +968,7 @@ void ERR_add_error_vdata(int num, va_list args) } str = p; } - BUF_strlcat(str, a, (size_t)s + 1); + OPENSSL_strlcat(str, a, (size_t)s + 1); } } ERR_set_error_data(str, ERR_TXT_MALLOCED | ERR_TXT_STRING); diff --git a/crypto/evp/e_chacha20_poly1305.c b/crypto/evp/e_chacha20_poly1305.c index 0d80f95e21..c3c72a1665 100644 --- a/crypto/evp/e_chacha20_poly1305.c +++ b/crypto/evp/e_chacha20_poly1305.c @@ -383,7 +383,7 @@ static int chacha20_poly1305_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, case EVP_CTRL_COPY: if (actx) { if ((((EVP_CIPHER_CTX *)ptr)->cipher_data = - BUF_memdup(actx,sizeof(*actx) + Poly1305_ctx_size())) + OPENSSL_memdup(actx,sizeof(*actx) + Poly1305_ctx_size())) == NULL) { EVPerr(EVP_F_CHACHA20_POLY1305_CTRL, EVP_R_COPY_ERROR); return 0; diff --git a/crypto/evp/evp_pbe.c b/crypto/evp/evp_pbe.c index e5b1739486..563634ec53 100644 --- a/crypto/evp/evp_pbe.c +++ b/crypto/evp/evp_pbe.c @@ -141,7 +141,7 @@ int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, char obj_tmp[80]; EVPerr(EVP_F_EVP_PBE_CIPHERINIT, EVP_R_UNKNOWN_PBE_ALGORITHM); if (!pbe_obj) - BUF_strlcpy(obj_tmp, "NULL", sizeof obj_tmp); + OPENSSL_strlcpy(obj_tmp, "NULL", sizeof obj_tmp); else i2t_ASN1_OBJECT(obj_tmp, sizeof obj_tmp, pbe_obj); ERR_add_error_data(2, "TYPE=", obj_tmp); diff --git a/crypto/lock.c b/crypto/lock.c index d24527a49b..f337c0d8de 100644 --- a/crypto/lock.c +++ b/crypto/lock.c @@ -215,7 +215,7 @@ int 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 ((str = OPENSSL_strdup(name)) == NULL) { CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID, ERR_R_MALLOC_FAILURE); return (0); } diff --git a/crypto/mem.c b/crypto/mem.c index 33a76d2d08..83a1547dc9 100644 --- a/crypto/mem.c +++ b/crypto/mem.c @@ -321,15 +321,6 @@ void *CRYPTO_zalloc(int num, const char *file, int line) return ret; } -char *CRYPTO_strdup(const char *str, const char *file, int line) -{ - char *ret = CRYPTO_malloc(strlen(str) + 1, file, line); - - if (ret != NULL) - strcpy(ret, str); - return ret; -} - void *CRYPTO_realloc(void *str, int num, const char *file, int line) { void *ret = NULL; diff --git a/crypto/mem_dbg.c b/crypto/mem_dbg.c index c2fe8af405..9a48410bea 100644 --- a/crypto/mem_dbg.c +++ b/crypto/mem_dbg.c @@ -704,7 +704,7 @@ static void print_leak_doall_arg(const MEM *m, MEM_LEAK *l) memcpy(buf + buf_len, amip->info, 128 - buf_len - 3); buf_len = 128 - 3; } else { - BUF_strlcpy(buf + buf_len, amip->info, sizeof buf - buf_len); + OPENSSL_strlcpy(buf + buf_len, amip->info, sizeof buf - buf_len); buf_len = strlen(buf); } BIO_snprintf(buf + buf_len, sizeof buf - buf_len, "\"\n"); diff --git a/crypto/o_str.c b/crypto/o_str.c index f2f9404db0..e96f62a2e8 100644 --- a/crypto/o_str.c +++ b/crypto/o_str.c @@ -58,7 +58,10 @@ */ #include +#include #include +#include +#include "internal/cryptlib.h" #include "internal/o_str.h" #if !defined(OPENSSL_IMPLEMENTS_strncasecmp) && \ @@ -114,3 +117,81 @@ int OPENSSL_memcmp(const void *v1, const void *v2, size_t n) return ret; } + +char *CRYPTO_strdup(const char *str, const char* file, int line) +{ + char *ret; + + if (str == NULL) + return NULL; + ret = CRYPTO_malloc(strlen(str) + 1, file, line); + if (ret != NULL) + strcpy(ret, str); + return ret; +} + +char *CRYPTO_strndup(const char *str, size_t s, const char* file, int line) +{ + const char *cp; + size_t maxlen; + char *ret; + + if (str == NULL) + return NULL; + + /* Get length. */ + for (cp = str, maxlen = s; maxlen-- != 0 && *cp != '\0'; ++cp) + continue; + maxlen = cp - str; + + ret = CRYPTO_malloc(maxlen + 1, file, line); + if (ret) { + memcpy(ret, str, maxlen); + ret[maxlen] = '\0'; + } + return ret; +} + +void *CRYPTO_memdup(const void *data, size_t siz, const char* file, int line) +{ + void *ret; + + if (data == NULL || siz >= INT_MAX) + return NULL; + + ret = CRYPTO_malloc(siz, file, line); + if (ret == NULL) { + CRYPTOerr(CRYPTO_F_CRYPTO_MEMDUP, ERR_R_MALLOC_FAILURE); + return NULL; + } + return memcpy(ret, data, siz); +} + +size_t OPENSSL_strnlen(const char *str, size_t maxlen) +{ + const char *p; + + for (p = str; maxlen-- != 0 && *p != '\0'; ++p) ; + + return p - str; +} + +size_t OPENSSL_strlcpy(char *dst, const char *src, size_t size) +{ + size_t l = 0; + for (; size > 1 && *src; size--) { + *dst++ = *src++; + l++; + } + if (size) + *dst = '\0'; + return l + strlen(src); +} + +size_t OPENSSL_strlcat(char *dst, const char *src, size_t size) +{ + size_t l = 0; + for (; size > 0 && *dst; size--, dst++) + l++; + return l + OPENSSL_strlcpy(dst, src, size); +} diff --git a/crypto/objects/obj_dat.c b/crypto/objects/obj_dat.c index e8a6b139dd..bda955651e 100644 --- a/crypto/objects/obj_dat.c +++ b/crypto/objects/obj_dat.c @@ -484,7 +484,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) s = OBJ_nid2sn(nid); if (s) { if (buf) - BUF_strlcpy(buf, s, buf_len); + OPENSSL_strlcpy(buf, s, buf_len); n = strlen(s); return n; } @@ -558,7 +558,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) *buf = '\0'; buf_len--; } - BUF_strlcpy(buf, bndec, buf_len); + OPENSSL_strlcpy(buf, bndec, buf_len); if (i > buf_len) { buf += buf_len; buf_len = 0; @@ -574,7 +574,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) BIO_snprintf(tbuf, sizeof tbuf, ".%lu", l); i = strlen(tbuf); if (buf && (buf_len > 0)) { - BUF_strlcpy(buf, tbuf, buf_len); + OPENSSL_strlcpy(buf, tbuf, buf_len); if (i > buf_len) { buf += buf_len; buf_len = 0; diff --git a/crypto/ocsp/ocsp_lib.c b/crypto/ocsp/ocsp_lib.c index 978429411f..092cc3727c 100644 --- a/crypto/ocsp/ocsp_lib.c +++ b/crypto/ocsp/ocsp_lib.c @@ -183,7 +183,7 @@ int OCSP_parse_url(const char *url, char **phost, char **pport, char **ppath, *ppath = NULL; /* dup the buffer since we are going to mess with it */ - buf = BUF_strdup(url); + buf = OPENSSL_strdup(url); if (!buf) goto mem_err; @@ -217,9 +217,9 @@ int OCSP_parse_url(const char *url, char **phost, char **pport, char **ppath, p = strchr(p, '/'); if (!p) - *ppath = BUF_strdup("/"); + *ppath = OPENSSL_strdup("/"); else { - *ppath = BUF_strdup(p); + *ppath = OPENSSL_strdup(p); /* Set start of path to 0 so hostname is valid */ *p = '\0'; } @@ -244,11 +244,11 @@ int OCSP_parse_url(const char *url, char **phost, char **pport, char **ppath, port = p + 1; } - *pport = BUF_strdup(port); + *pport = OPENSSL_strdup(port); if (!*pport) goto mem_err; - *phost = BUF_strdup(host); + *phost = OPENSSL_strdup(host); if (!*phost) goto mem_err; diff --git a/crypto/pem/pem_lib.c b/crypto/pem/pem_lib.c index 42a8583fb1..465e2eec8f 100644 --- a/crypto/pem/pem_lib.c +++ b/crypto/pem/pem_lib.c @@ -134,9 +134,9 @@ void PEM_proc_type(char *buf, int type) else str = "BAD-TYPE"; - BUF_strlcat(buf, "Proc-Type: 4,", PEM_BUFSIZE); - BUF_strlcat(buf, str, PEM_BUFSIZE); - BUF_strlcat(buf, "\n", PEM_BUFSIZE); + OPENSSL_strlcat(buf, "Proc-Type: 4,", PEM_BUFSIZE); + OPENSSL_strlcat(buf, str, PEM_BUFSIZE); + OPENSSL_strlcat(buf, "\n", PEM_BUFSIZE); } void PEM_dek_info(char *buf, const char *type, int len, char *str) @@ -145,9 +145,9 @@ void PEM_dek_info(char *buf, const char *type, int len, char *str) long i; int j; - BUF_strlcat(buf, "DEK-Info: ", PEM_BUFSIZE); - BUF_strlcat(buf, type, PEM_BUFSIZE); - BUF_strlcat(buf, ",", PEM_BUFSIZE); + OPENSSL_strlcat(buf, "DEK-Info: ", PEM_BUFSIZE); + OPENSSL_strlcat(buf, type, PEM_BUFSIZE); + OPENSSL_strlcat(buf, ",", PEM_BUFSIZE); j = strlen(buf); if (j + (len * 2) + 1 > PEM_BUFSIZE) return; diff --git a/crypto/rand/Makefile b/crypto/rand/Makefile index adcbb82db0..bc8c624742 100644 --- a/crypto/rand/Makefile +++ b/crypto/rand/Makefile @@ -72,9 +72,11 @@ md_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h md_rand.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h md_rand.o: ../../include/openssl/sha.h ../../include/openssl/stack.h md_rand.o: ../../include/openssl/symhacks.h md_rand.c rand_lcl.h -rand_egd.o: ../../include/openssl/buffer.h ../../include/openssl/e_os2.h +rand_egd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h rand_egd.o: ../../include/openssl/opensslconf.h -rand_egd.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h +rand_egd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h +rand_egd.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h +rand_egd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h rand_egd.o: rand_egd.c rand_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h rand_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h diff --git a/crypto/rand/rand_egd.c b/crypto/rand/rand_egd.c index d062dd6cd4..ea3621c44f 100644 --- a/crypto/rand/rand_egd.c +++ b/crypto/rand/rand_egd.c @@ -54,9 +54,9 @@ * */ +#include #include #include -#include /*- * Query the EGD . @@ -144,7 +144,7 @@ int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes) addr.sun_family = AF_UNIX; if (strlen(path) >= sizeof(addr.sun_path)) return (-1); - BUF_strlcpy(addr.sun_path, path, sizeof addr.sun_path); + OPENSSL_strlcpy(addr.sun_path, path, sizeof addr.sun_path); len = offsetof(struct sockaddr_un, sun_path) + strlen(path); fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd == -1) diff --git a/crypto/rand/randfile.c b/crypto/rand/randfile.c index e15464651c..a1b0c4dcfe 100644 --- a/crypto/rand/randfile.c +++ b/crypto/rand/randfile.c @@ -294,7 +294,7 @@ const char *RAND_file_name(char *buf, size_t size) if (OPENSSL_issetugid() == 0) s = getenv("RANDFILE"); if (s != NULL && *s && strlen(s) + 1 < size) { - if (BUF_strlcpy(buf, s, size) >= size) + if (OPENSSL_strlcpy(buf, s, size) >= size) return NULL; } else { if (OPENSSL_issetugid() == 0) @@ -305,11 +305,11 @@ const char *RAND_file_name(char *buf, size_t size) } #endif if (s && *s && strlen(s) + strlen(RFILE) + 2 < size) { - BUF_strlcpy(buf, s, size); + OPENSSL_strlcpy(buf, s, size); #ifndef OPENSSL_SYS_VMS - BUF_strlcat(buf, "/", size); + OPENSSL_strlcat(buf, "/", size); #endif - BUF_strlcat(buf, RFILE, size); + OPENSSL_strlcat(buf, RFILE, size); } else buf[0] = '\0'; /* no file name */ } @@ -324,11 +324,11 @@ const char *RAND_file_name(char *buf, size_t size) */ if (!buf[0]) - if (BUF_strlcpy(buf, "/dev/arandom", size) >= size) { + if (OPENSSL_strlcpy(buf, "/dev/arandom", size) >= size) { return (NULL); } if (stat(buf, &sb) == -1) - if (BUF_strlcpy(buf, "/dev/arandom", size) >= size) { + if (OPENSSL_strlcpy(buf, "/dev/arandom", size) >= size) { return (NULL); } #endif diff --git a/crypto/rsa/rsa_pmeth.c b/crypto/rsa/rsa_pmeth.c index 8c8e0e86e4..f5f8c1f159 100644 --- a/crypto/rsa/rsa_pmeth.c +++ b/crypto/rsa/rsa_pmeth.c @@ -128,7 +128,7 @@ static int pkey_rsa_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src) dctx->mgf1md = sctx->mgf1md; if (sctx->oaep_label) { OPENSSL_free(dctx->oaep_label); - dctx->oaep_label = BUF_memdup(sctx->oaep_label, sctx->oaep_labellen); + dctx->oaep_label = OPENSSL_memdup(sctx->oaep_label, sctx->oaep_labellen); if (!dctx->oaep_label) return 0; dctx->oaep_labellen = sctx->oaep_labellen; diff --git a/crypto/srp/srp_vfy.c b/crypto/srp/srp_vfy.c index 1be68f2340..65c763c929 100644 --- a/crypto/srp/srp_vfy.c +++ b/crypto/srp/srp_vfy.c @@ -220,9 +220,9 @@ static void SRP_user_pwd_set_gN(SRP_user_pwd *vinfo, const BIGNUM *g, static int SRP_user_pwd_set_ids(SRP_user_pwd *vinfo, const char *id, const char *info) { - if (id != NULL && NULL == (vinfo->id = BUF_strdup(id))) + if (id != NULL && NULL == (vinfo->id = OPENSSL_strdup(id))) return 0; - return (info == NULL || NULL != (vinfo->info = BUF_strdup(info))); + return (info == NULL || NULL != (vinfo->info = OPENSSL_strdup(info))); } static int SRP_user_pwd_set_sv(SRP_user_pwd *vinfo, const char *s, @@ -261,7 +261,7 @@ SRP_VBASE *SRP_VBASE_new(char *seed_key) vb->default_g = NULL; vb->default_N = NULL; vb->seed_key = NULL; - if ((seed_key != NULL) && (vb->seed_key = BUF_strdup(seed_key)) == NULL) { + if ((seed_key != NULL) && (vb->seed_key = OPENSSL_strdup(seed_key)) == NULL) { sk_SRP_user_pwd_free(vb->users_pwd); sk_SRP_gN_cache_free(vb->gN_cache); OPENSSL_free(vb); @@ -289,7 +289,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 ((newgN->b64_bn = OPENSSL_strdup(ch)) == NULL) goto err; len = t_fromb64(tmp, ch); @@ -394,7 +394,7 @@ int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file) if ((gN = OPENSSL_malloc(sizeof(*gN))) == NULL) goto err; - if ((gN->id = BUF_strdup(pp[DB_srpid])) == NULL + if ((gN->id = OPENSSL_strdup(pp[DB_srpid])) == NULL || (gN->N = SRP_gN_place_bn(vb->gN_cache, pp[DB_srpverifier])) == NULL || (gN->g = SRP_gN_place_bn(vb->gN_cache, pp[DB_srpsalt])) diff --git a/crypto/store/str_lib.c b/crypto/store/str_lib.c index d5ecdbdbf4..301d0c0c6b 100644 --- a/crypto/store/str_lib.c +++ b/crypto/store/str_lib.c @@ -1305,7 +1305,7 @@ int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, return 0; } if (!ATTR_IS_SET(attrs, code)) { - if ((attrs->values[code].cstring = BUF_strndup(cstr, cstr_size))) + if ((attrs->values[code].cstring = OPENSSL_strndup(cstr, cstr_size))) return 1; STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, ERR_R_MALLOC_FAILURE); return 0; @@ -1324,7 +1324,7 @@ int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code, } if (!ATTR_IS_SET(attrs, code)) { if ((attrs->values[code].sha1string = - (unsigned char *)BUF_memdup(sha1str, sha1str_size))) + (unsigned char *)OPENSSL_memdup(sha1str, sha1str_size))) return 1; STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR, ERR_R_MALLOC_FAILURE); return 0; diff --git a/crypto/store/str_meth.c b/crypto/store/str_meth.c index f9ce8bb4e7..5e0f4bd276 100644 --- a/crypto/store/str_meth.c +++ b/crypto/store/str_meth.c @@ -66,7 +66,7 @@ STORE_METHOD *STORE_create_method(char *name) STORE_METHOD *store_method = OPENSSL_zalloc(sizeof(*store_method)); if (store_method != NULL) - store_method->name = BUF_strdup(name); + store_method->name = OPENSSL_strdup(name); return store_method; } diff --git a/crypto/ui/ui_lib.c b/crypto/ui/ui_lib.c index d2ac28ba7f..ea3ec139e1 100644 --- a/crypto/ui/ui_lib.c +++ b/crypto/ui/ui_lib.c @@ -238,7 +238,7 @@ int UI_dup_input_string(UI *ui, const char *prompt, int flags, char *prompt_copy = NULL; if (prompt) { - prompt_copy = BUF_strdup(prompt); + prompt_copy = OPENSSL_strdup(prompt); if (prompt_copy == NULL) { UIerr(UI_F_UI_DUP_INPUT_STRING, ERR_R_MALLOC_FAILURE); return 0; @@ -266,7 +266,7 @@ int UI_dup_verify_string(UI *ui, const char *prompt, int flags, char *prompt_copy = NULL; if (prompt) { - prompt_copy = BUF_strdup(prompt); + prompt_copy = OPENSSL_strdup(prompt); if (prompt_copy == NULL) { UIerr(UI_F_UI_DUP_VERIFY_STRING, ERR_R_MALLOC_FAILURE); return -1; @@ -297,7 +297,7 @@ int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, char *cancel_chars_copy = NULL; if (prompt) { - prompt_copy = BUF_strdup(prompt); + prompt_copy = OPENSSL_strdup(prompt); if (prompt_copy == NULL) { UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); goto err; @@ -305,7 +305,7 @@ int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, } if (action_desc) { - action_desc_copy = BUF_strdup(action_desc); + action_desc_copy = OPENSSL_strdup(action_desc); if (action_desc_copy == NULL) { UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); goto err; @@ -313,7 +313,7 @@ int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, } if (ok_chars) { - ok_chars_copy = BUF_strdup(ok_chars); + ok_chars_copy = OPENSSL_strdup(ok_chars); if (ok_chars_copy == NULL) { UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); goto err; @@ -321,7 +321,7 @@ int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc, } if (cancel_chars) { - cancel_chars_copy = BUF_strdup(cancel_chars); + cancel_chars_copy = OPENSSL_strdup(cancel_chars); if (cancel_chars_copy == NULL) { UIerr(UI_F_UI_DUP_INPUT_BOOLEAN, ERR_R_MALLOC_FAILURE); goto err; @@ -350,7 +350,7 @@ int UI_dup_info_string(UI *ui, const char *text) char *text_copy = NULL; if (text) { - text_copy = BUF_strdup(text); + text_copy = OPENSSL_strdup(text); if (text_copy == NULL) { UIerr(UI_F_UI_DUP_INFO_STRING, ERR_R_MALLOC_FAILURE); return -1; @@ -372,7 +372,7 @@ int UI_dup_error_string(UI *ui, const char *text) char *text_copy = NULL; if (text) { - text_copy = BUF_strdup(text); + text_copy = OPENSSL_strdup(text); if (text_copy == NULL) { UIerr(UI_F_UI_DUP_ERROR_STRING, ERR_R_MALLOC_FAILURE); return -1; @@ -405,13 +405,13 @@ char *UI_construct_prompt(UI *ui, const char *object_desc, prompt = OPENSSL_malloc(len + 1); if (prompt == NULL) return NULL; - BUF_strlcpy(prompt, prompt1, len + 1); - BUF_strlcat(prompt, object_desc, len + 1); + OPENSSL_strlcpy(prompt, prompt1, len + 1); + OPENSSL_strlcat(prompt, object_desc, len + 1); if (object_name) { - BUF_strlcat(prompt, prompt2, len + 1); - BUF_strlcat(prompt, object_name, len + 1); + OPENSSL_strlcat(prompt, prompt2, len + 1); + OPENSSL_strlcat(prompt, object_name, len + 1); } - BUF_strlcat(prompt, prompt3, len + 1); + OPENSSL_strlcat(prompt, prompt3, len + 1); } return prompt; } @@ -575,7 +575,7 @@ UI_METHOD *UI_create_method(char *name) UI_METHOD *ui_method = OPENSSL_zalloc(sizeof(*ui_method)); if (ui_method != NULL) - ui_method->name = BUF_strdup(name); + ui_method->name = OPENSSL_strdup(name); return ui_method; } @@ -822,7 +822,7 @@ int UI_set_result(UI *ui, UI_STRING *uis, const char *result) return -1; } - BUF_strlcpy(uis->result_buf, result, + OPENSSL_strlcpy(uis->result_buf, result, uis->_.string_data.result_maxsize + 1); break; case UIT_BOOLEAN: diff --git a/crypto/x509/x509_trs.c b/crypto/x509/x509_trs.c index 6e3616e2f2..27ee47590d 100644 --- a/crypto/x509/x509_trs.c +++ b/crypto/x509/x509_trs.c @@ -201,7 +201,7 @@ int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int), if (trtmp->flags & X509_TRUST_DYNAMIC_NAME) OPENSSL_free(trtmp->name); /* dup supplied name */ - if ((trtmp->name = BUF_strdup(name)) == NULL) { + if ((trtmp->name = OPENSSL_strdup(name)) == NULL) { X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE); return 0; } diff --git a/crypto/x509/x509_vpm.c b/crypto/x509/x509_vpm.c index 0188114b0f..2a15f82ea1 100644 --- a/crypto/x509/x509_vpm.c +++ b/crypto/x509/x509_vpm.c @@ -106,7 +106,7 @@ static int int_x509_param_set_hosts(X509_VERIFY_PARAM *vpm, int mode, if (name == NULL || namelen == 0) return 1; - copy = BUF_strndup(name, namelen); + copy = OPENSSL_strndup(name, namelen); if (copy == NULL) return 0; @@ -308,10 +308,10 @@ static int int_x509_param_set1(char **pdest, size_t *pdestlen, void *tmp; if (src) { if (srclen == 0) { - tmp = BUF_strdup(src); + tmp = OPENSSL_strdup(src); srclen = strlen(src); } else - tmp = BUF_memdup(src, srclen); + tmp = OPENSSL_memdup(src, srclen); if (!tmp) return 0; } else { @@ -328,7 +328,7 @@ static int int_x509_param_set1(char **pdest, size_t *pdestlen, int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name) { OPENSSL_free(param->name); - param->name = BUF_strdup(name); + param->name = OPENSSL_strdup(name); if (param->name) return 1; return 0; diff --git a/crypto/x509v3/v3_addr.c b/crypto/x509v3/v3_addr.c index f4a3bcbeda..13aa7a86fa 100644 --- a/crypto/x509v3/v3_addr.c +++ b/crypto/x509v3/v3_addr.c @@ -980,7 +980,7 @@ static void *v2i_IPAddrBlocks(const struct v3_ext_method *method, length = length_from_afi(afi); /* - * Handle SAFI, if any, and BUF_strdup() so we can null-terminate + * Handle SAFI, if any, and OPENSSL_strdup() so we can null-terminate * the other input values. */ if (safi != NULL) { @@ -992,9 +992,9 @@ static void *v2i_IPAddrBlocks(const struct v3_ext_method *method, goto err; } t += strspn(t, " \t"); - s = BUF_strdup(t); + s = OPENSSL_strdup(t); } else { - s = BUF_strdup(val->value); + s = OPENSSL_strdup(val->value); } if (s == NULL) { X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE); diff --git a/crypto/x509v3/v3_asid.c b/crypto/x509v3/v3_asid.c index af527ebc1b..3e10d7ef7a 100644 --- a/crypto/x509v3/v3_asid.c +++ b/crypto/x509v3/v3_asid.c @@ -619,7 +619,7 @@ static void *v2i_ASIdentifiers(const struct v3_ext_method *method, goto err; } } else { - char *s = BUF_strdup(val->value); + char *s = OPENSSL_strdup(val->value); if (s == NULL) { X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE); goto err; diff --git a/crypto/x509v3/v3_enum.c b/crypto/x509v3/v3_enum.c index d2f895d5d5..dcdd0c674d 100644 --- a/crypto/x509v3/v3_enum.c +++ b/crypto/x509v3/v3_enum.c @@ -95,7 +95,7 @@ char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *method, ASN1_ENUMERATED *e) strval = ASN1_ENUMERATED_get(e); for (enam = method->usr_data; enam->lname; enam++) { if (strval == enam->bitnum) - return BUF_strdup(enam->lname); + return OPENSSL_strdup(enam->lname); } return i2s_ASN1_ENUMERATED(method, e); } diff --git a/crypto/x509v3/v3_info.c b/crypto/x509v3/v3_info.c index 4e38ad33c0..f8888c2dbf 100644 --- a/crypto/x509v3/v3_info.c +++ b/crypto/x509v3/v3_info.c @@ -131,9 +131,9 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD ERR_R_MALLOC_FAILURE); return NULL; } - BUF_strlcpy(ntmp, objtmp, nlen); - BUF_strlcat(ntmp, " - ", nlen); - BUF_strlcat(ntmp, vtmp->name, nlen); + OPENSSL_strlcpy(ntmp, objtmp, nlen); + OPENSSL_strlcat(ntmp, " - ", nlen); + OPENSSL_strlcat(ntmp, vtmp->name, nlen); OPENSSL_free(vtmp->name); vtmp->name = ntmp; diff --git a/crypto/x509v3/v3_purp.c b/crypto/x509v3/v3_purp.c index 90b3abcff7..3724e664eb 100644 --- a/crypto/x509v3/v3_purp.c +++ b/crypto/x509v3/v3_purp.c @@ -225,8 +225,8 @@ int X509_PURPOSE_add(int id, int trust, int flags, OPENSSL_free(ptmp->sname); } /* dup supplied name */ - ptmp->name = BUF_strdup(name); - ptmp->sname = BUF_strdup(sname); + ptmp->name = OPENSSL_strdup(name); + ptmp->sname = OPENSSL_strdup(sname); if (!ptmp->name || !ptmp->sname) { X509V3err(X509V3_F_X509_PURPOSE_ADD, ERR_R_MALLOC_FAILURE); return 0; diff --git a/crypto/x509v3/v3_utl.c b/crypto/x509v3/v3_utl.c index 8481749a1f..c9e74f4c4b 100644 --- a/crypto/x509v3/v3_utl.c +++ b/crypto/x509v3/v3_utl.c @@ -86,9 +86,9 @@ int X509V3_add_value(const char *name, const char *value, CONF_VALUE *vtmp = NULL; char *tname = NULL, *tvalue = NULL; - if (name && (tname = BUF_strdup(name)) == NULL) + if (name && (tname = OPENSSL_strdup(name)) == NULL) goto err; - if (value && (tvalue = BUF_strdup(value)) == NULL) + if (value && (tvalue = OPENSSL_strdup(value)) == NULL) goto err; if ((vtmp = OPENSSL_malloc(sizeof(*vtmp))) == NULL) goto err; @@ -296,7 +296,7 @@ STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line) char *linebuf; int state; /* We are going to modify the line so copy it first */ - linebuf = BUF_strdup(line); + linebuf = OPENSSL_strdup(line); if (linebuf == NULL) { X509V3err(X509V3_F_X509V3_PARSE_LIST, ERR_R_MALLOC_FAILURE); goto err; @@ -617,7 +617,7 @@ static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, ASN1_IA5STRING *email) /* Don't add duplicates */ if (sk_OPENSSL_STRING_find(*sk, (char *)email->data) != -1) return 1; - emtmp = BUF_strdup((char *)email->data); + emtmp = OPENSSL_strdup((char *)email->data); if (emtmp == NULL || !sk_OPENSSL_STRING_push(*sk, emtmp)) { X509_email_free(*sk); *sk = NULL; @@ -899,7 +899,7 @@ static int do_check_string(ASN1_STRING *a, int cmp_type, equal_fn equal, else if (a->length == (int)blen && !memcmp(a->data, b, blen)) rv = 1; if (rv > 0 && peername) - *peername = BUF_strndup((char *)a->data, a->length); + *peername = OPENSSL_strndup((char *)a->data, a->length); } else { int astrlen; unsigned char *astr; @@ -913,7 +913,7 @@ static int do_check_string(ASN1_STRING *a, int cmp_type, equal_fn equal, } rv = equal(astr, astrlen, (unsigned char *)b, blen, flags); if (rv > 0 && peername) - *peername = BUF_strndup((char *)astr, astrlen); + *peername = OPENSSL_strndup((char *)astr, astrlen); OPENSSL_free(astr); } return rv; @@ -1099,7 +1099,7 @@ ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc) p = strchr(ipasc, '/'); if (!p) return NULL; - iptmp = BUF_strdup(ipasc); + iptmp = OPENSSL_strdup(ipasc); if (!iptmp) return NULL; p = iptmp + (p - ipasc); diff --git a/doc/crypto/buffer.pod b/doc/crypto/buffer.pod index 135163500f..a2543e8be0 100644 --- a/doc/crypto/buffer.pod +++ b/doc/crypto/buffer.pod @@ -5,7 +5,6 @@ BUF_MEM_new, BUF_MEM_new_ex, BUF_MEM_free, BUF_MEM_grow - simple character array structure -BUF_strdup, BUF_strndup, BUF_memdup, BUF_strlcpy, BUF_strlcat - standard C library equivalents =head1 SYNOPSIS @@ -22,18 +21,6 @@ standard C library equivalents int BUF_MEM_grow(BUF_MEM *str, int len); - char *BUF_strdup(const char *str); - - char *BUF_strndup(const char *str, size_t siz); - - void *BUF_memdup(const void *data, size_t siz); - - size_t BUF_strlcpy(char *dst, const char *src, size_t size); - - size_t BUF_strlcat(char *dst, const char *src, size_t size); - - size_t BUF_strnlen(const char *str, size_t maxlen); - =head1 DESCRIPTION The buffer library handles simple character arrays. Buffers are used for @@ -52,18 +39,6 @@ BUF_MEM_grow() changes the size of an already existing buffer to B. Any data already in the buffer is preserved if it increases in size. -BUF_strdup(), BUF_strndup(), BUF_memdup(), BUF_strlcpy(), -BUF_strlcat() and BUF_strnlen are equivalents of the standard C -library functions. The dup() functions use OPENSSL_malloc() underneath -and so should be used in preference to the standard library for memory -leak checking or replacing the malloc() function. - -Memory allocated from these functions should be freed up using the -OPENSSL_free() function. - -BUF_strndup makes the explicit guarantee that it will never read past -the first B bytes of B. - =head1 RETURN VALUES BUF_MEM_new() returns the buffer or NULL on error. diff --git a/engines/ccgost/gost_ctl.c b/engines/ccgost/gost_ctl.c index 31b95a0d21..20a07dfe59 100644 --- a/engines/ccgost/gost_ctl.c +++ b/engines/ccgost/gost_ctl.c @@ -67,7 +67,7 @@ const char *get_gost_engine_param(int param) tmp = getenv(gost_envnames[param]); if (tmp) { OPENSSL_free(gost_params[param]); - gost_params[param] = BUF_strdup(tmp); + gost_params[param] = OPENSSL_strdup(tmp); return gost_params[param]; } return NULL; @@ -85,7 +85,7 @@ int gost_set_default_param(int param, const char *value) if (!tmp) tmp = value; OPENSSL_free(gost_params[param]); - gost_params[param] = BUF_strdup(tmp); + gost_params[param] = OPENSSL_strdup(tmp); return 1; } diff --git a/engines/e_capi.c b/engines/e_capi.c index 1e41b267e4..8ef986fd43 100644 --- a/engines/e_capi.c +++ b/engines/e_capi.c @@ -361,7 +361,7 @@ static int capi_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) case CAPI_CMD_STORE_NAME: OPENSSL_free(ctx->storename); - ctx->storename = BUF_strdup(p); + ctx->storename = OPENSSL_strdup(p); CAPI_trace(ctx, "Setting store name to %s\n", p); break; @@ -382,7 +382,7 @@ static int capi_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) break; case CAPI_CMD_DEBUG_FILE: - ctx->debug_file = BUF_strdup(p); + ctx->debug_file = OPENSSL_strdup(p); CAPI_trace(ctx, "Setting debug file to %s\n", ctx->debug_file); break; @@ -1635,7 +1635,7 @@ static int capi_ctx_set_provname(CAPI_CTX * ctx, LPSTR pname, DWORD type, CryptReleaseContext(hprov, 0); } OPENSSL_free(ctx->cspname); - ctx->cspname = BUF_strdup(pname); + ctx->cspname = OPENSSL_strdup(pname); ctx->csptype = type; return 1; } diff --git a/engines/e_chil.c b/engines/e_chil.c index 8696c9ac2c..924de8ca48 100644 --- a/engines/e_chil.c +++ b/engines/e_chil.c @@ -476,7 +476,7 @@ static const char *get_HWCRHK_LIBNAME(void) static long set_HWCRHK_LIBNAME(const char *name) { free_HWCRHK_LIBNAME(); - return (((HWCRHK_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0); + return (((HWCRHK_LIBNAME = OPENSSL_strdup(name)) != NULL) ? 1 : 0); } static const char *n_hwcrhk_Init = "HWCryptoHook_Init"; diff --git a/engines/e_ubsec.c b/engines/e_ubsec.c index eefd37f3ad..f59dfa6872 100644 --- a/engines/e_ubsec.c +++ b/engines/e_ubsec.c @@ -346,7 +346,7 @@ static void free_UBSEC_LIBNAME(void) static long set_UBSEC_LIBNAME(const char *name) { free_UBSEC_LIBNAME(); - return (((UBSEC_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0); + return (((UBSEC_LIBNAME = OPENSSL_strdup(name)) != NULL) ? 1 : 0); } static const char *UBSEC_F1 = "ubsec_bytes_to_bits"; diff --git a/include/openssl/buffer.h b/include/openssl/buffer.h index f22ed09713..47d68f81c3 100644 --- a/include/openssl/buffer.h +++ b/include/openssl/buffer.h @@ -60,6 +60,10 @@ # define HEADER_BUFFER_H # include +# ifndef HEADER_CRYPTO_H +# include +# endif + #ifdef __cplusplus extern "C" { @@ -71,9 +75,17 @@ extern "C" { # include # endif -/* Already declared in ossl_typ.h */ -/* typedef struct buf_mem_st BUF_MEM; */ - +/* + * These names are outdated as of OpenSSL 1.1; a future release + * will move them to be deprecated. + */ +# define BUF_strdup(s) OPENSSL_strdup(s) +# define BUF_strndup(s, size) OPENSSL_strndup(s, size) +# define BUF_memdup(data, size) OPENSSL_memdup(data, size) +# define BUF_strlcpy(dst, src, size) OPENSSL_strlcpy(dst, src, size) +# define BUF_strlcat(dst, src, size) OPENSSL_strlcat(dst, src, size) +# define BUF_strnlen(str, maxlen) OPENSSL_strnlen(str, maxlen) + struct buf_mem_st { size_t length; /* current number of bytes */ char *data; @@ -88,22 +100,8 @@ BUF_MEM *BUF_MEM_new_ex(unsigned long flags); void BUF_MEM_free(BUF_MEM *a); size_t BUF_MEM_grow(BUF_MEM *str, size_t len); size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len); -size_t BUF_strnlen(const char *str, size_t maxlen); -char *BUF_strdup(const char *str); - -/* - * Like strndup, but in addition, explicitly guarantees to never read past the - * first |siz| bytes of |str|. - */ -char *BUF_strndup(const char *str, size_t siz); - -void *BUF_memdup(const void *data, size_t siz); void BUF_reverse(unsigned char *out, unsigned char *in, size_t siz); -/* safe string functions */ -size_t BUF_strlcpy(char *dst, const char *src, size_t siz); -size_t BUF_strlcat(char *dst, const char *src, size_t siz); - /* BEGIN ERROR CODES */ /* * The following lines are auto generated by the script mkerr.pl. Any changes @@ -114,12 +112,9 @@ void ERR_load_BUF_strings(void); /* Error codes for the BUF functions. */ /* Function codes. */ -# define BUF_F_BUF_MEMDUP 103 # define BUF_F_BUF_MEM_GROW 100 # define BUF_F_BUF_MEM_GROW_CLEAN 105 # define BUF_F_BUF_MEM_NEW 101 -# define BUF_F_BUF_STRDUP 102 -# define BUF_F_BUF_STRNDUP 104 /* Reason codes. */ diff --git a/include/openssl/crypto.h b/include/openssl/crypto.h index 78d86b12f1..977481b57d 100644 --- a/include/openssl/crypto.h +++ b/include/openssl/crypto.h @@ -319,18 +319,25 @@ int CRYPTO_is_mem_check_on(void); # define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE) # define is_MemCheck_on() CRYPTO_is_mem_check_on() -# define OPENSSL_malloc(num) CRYPTO_malloc((int)num,__FILE__,__LINE__) -# define OPENSSL_zalloc(num) CRYPTO_zalloc((int)num,__FILE__,__LINE__) -# define OPENSSL_strdup(str) CRYPTO_strdup((str),__FILE__,__LINE__) +# define OPENSSL_malloc(num) CRYPTO_malloc((int)num, __FILE__, __LINE__) +# define OPENSSL_zalloc(num) CRYPTO_zalloc((int)num, __FILE__, __LINE__) +# define OPENSSL_memdup(str, s) CRYPTO_memdup((str), s, __FILE__, __LINE__) +# define OPENSSL_strdup(str) CRYPTO_strdup((str), __FILE__, __LINE__) +# define OPENSSL_strndup(str, s) CRYPTO_strndup((str), (s), __FILE__, __LINE__) # define OPENSSL_realloc(addr,num) \ - CRYPTO_realloc((char *)addr,(int)num,__FILE__,__LINE__) + CRYPTO_realloc((char *)addr, (int)num, __FILE__, __LINE__) # define OPENSSL_realloc_clean(addr,old_num,num) \ - CRYPTO_realloc_clean(addr,old_num,num,__FILE__,__LINE__) + CRYPTO_realloc_clean(addr, old_num, num, __FILE__, __LINE__) # define OPENSSL_remalloc(addr,num) \ - CRYPTO_remalloc((char **)addr,(int)num,__FILE__,__LINE__) + CRYPTO_remalloc((char **)addr, (int)num, __FILE__, __LINE__) # define OPENSSL_clear_free(addr, num) CRYPTO_clear_free(addr, num) # define OPENSSL_free(addr) CRYPTO_free(addr) +size_t OPENSSL_strlcpy(char *dst, const char *src, size_t siz); +size_t OPENSSL_strlcpy(char *dst, const char *src, size_t siz); +size_t OPENSSL_strlcat(char *dst, const char *src, size_t siz); +size_t OPENSSL_strnlen(const char *str, size_t maxlen); + # define OPENSSL_MALLOC_MAX_NELEMS(type) (((1U<<(sizeof(int)*8-1))-1)/sizeof(type)) unsigned long OpenSSL_version_num(void); @@ -469,7 +476,9 @@ void CRYPTO_get_mem_debug_functions(void (**m) void *CRYPTO_malloc(int num, const char *file, int line); void *CRYPTO_zalloc(int num, const char *file, int line); +void *CRYPTO_memdup(const void *str, size_t siz, const char *file, int line); char *CRYPTO_strdup(const char *str, const char *file, int line); +char *CRYPTO_strndup(const char *str, size_t s, const char *file, int line); void CRYPTO_free(void *ptr); void CRYPTO_clear_free(void *ptr, size_t num); void *CRYPTO_realloc(void *addr, int num, const char *file, int line); @@ -585,6 +594,7 @@ void ERR_load_CRYPTO_strings(void); # define CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX 100 # define CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID 103 # define CRYPTO_F_CRYPTO_GET_NEW_LOCKID 101 +# define CRYPTO_F_CRYPTO_MEMDUP 115 # define CRYPTO_F_CRYPTO_NEW_EX_DATA 112 # define CRYPTO_F_CRYPTO_SET_EX_DATA 102 # define CRYPTO_F_DEF_ADD_INDEX 104 diff --git a/ssl/packet_locl.h b/ssl/packet_locl.h index cb61a93ad3..c0ab8257b7 100644 --- a/ssl/packet_locl.h +++ b/ssl/packet_locl.h @@ -408,8 +408,7 @@ __owur static inline int PACKET_memdup(const PACKET *pkt, unsigned char **data, if (length == 0) return 1; - *data = BUF_memdup(pkt->curr, length); - + *data = OPENSSL_memdup(pkt->curr, length); if (*data == NULL) return 0; @@ -432,7 +431,7 @@ __owur static inline int PACKET_strndup(const PACKET *pkt, char **data) OPENSSL_free(*data); /* This will succeed on an empty packet, unless pkt->curr == NULL. */ - *data = BUF_strndup((const char*)pkt->curr, PACKET_remaining(pkt)); + *data = OPENSSL_strndup((const char*)pkt->curr, PACKET_remaining(pkt)); return (*data != NULL); } diff --git a/ssl/s3_lib.c b/ssl/s3_lib.c index a61ca625f7..54ba298394 100644 --- a/ssl/s3_lib.c +++ b/ssl/s3_lib.c @@ -3836,7 +3836,7 @@ void ssl3_clear(SSL *s) #ifndef OPENSSL_NO_SRP static char *srp_password_from_info_cb(SSL *s, void *arg) { - return BUF_strdup(s->srp_ctx.info); + return OPENSSL_strdup(s->srp_ctx.info); } #endif @@ -3940,7 +3940,7 @@ long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg) SSLerr(SSL_F_SSL3_CTRL, SSL_R_SSL3_EXT_INVALID_SERVERNAME); return 0; } - if ((s->tlsext_hostname = BUF_strdup((char *)parg)) == NULL) { + if ((s->tlsext_hostname = OPENSSL_strdup((char *)parg)) == NULL) { SSLerr(SSL_F_SSL3_CTRL, ERR_R_INTERNAL_ERROR); return 0; } @@ -4359,7 +4359,7 @@ long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg) SSLerr(SSL_F_SSL3_CTX_CTRL, SSL_R_INVALID_SRP_USERNAME); return 0; } - if ((ctx->srp_ctx.login = BUF_strdup((char *)parg)) == NULL) { + if ((ctx->srp_ctx.login = OPENSSL_strdup((char *)parg)) == NULL) { SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_INTERNAL_ERROR); return 0; } diff --git a/ssl/ssl_asn1.c b/ssl/ssl_asn1.c index 1d11b21765..69c4d12a90 100644 --- a/ssl/ssl_asn1.c +++ b/ssl/ssl_asn1.c @@ -255,7 +255,7 @@ int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp) /* Utility functions for d2i_SSL_SESSION */ -/* BUF_strndup an OCTET STRING */ +/* OPENSSL_strndup an OCTET STRING */ static int ssl_session_strndup(char **pdst, ASN1_OCTET_STRING *src) { @@ -263,7 +263,7 @@ static int ssl_session_strndup(char **pdst, ASN1_OCTET_STRING *src) *pdst = NULL; if (src == NULL) return 1; - *pdst = BUF_strndup((char *)src->data, src->length); + *pdst = OPENSSL_strndup((char *)src->data, src->length); if (*pdst == NULL) return 0; return 1; diff --git a/ssl/ssl_cert.c b/ssl/ssl_cert.c index 80dc409478..41e34ce1d8 100644 --- a/ssl/ssl_cert.c +++ b/ssl/ssl_cert.c @@ -315,7 +315,7 @@ CERT *ssl_cert_dup(CERT *cert) goto err; #ifndef OPENSSL_NO_PSK if (cert->psk_identity_hint) { - ret->psk_identity_hint = BUF_strdup(cert->psk_identity_hint); + ret->psk_identity_hint = OPENSSL_strdup(cert->psk_identity_hint); if (ret->psk_identity_hint == NULL) goto err; } diff --git a/ssl/ssl_conf.c b/ssl/ssl_conf.c index ce52569ce9..21aa2652fc 100644 --- a/ssl/ssl_conf.c +++ b/ssl/ssl_conf.c @@ -368,7 +368,7 @@ static int cmd_Certificate(SSL_CONF_CTX *cctx, const char *value) if (rv > 0 && c && cctx->flags & SSL_CONF_FLAG_REQUIRE_PRIVATE) { char **pfilename = &cctx->cert_filename[c->key - c->pkeys]; OPENSSL_free(*pfilename); - *pfilename = BUF_strdup(value); + *pfilename = OPENSSL_strdup(value); if (!*pfilename) rv = 0; } @@ -812,7 +812,7 @@ int SSL_CONF_CTX_set1_prefix(SSL_CONF_CTX *cctx, const char *pre) { char *tmp = NULL; if (pre) { - tmp = BUF_strdup(pre); + tmp = OPENSSL_strdup(pre); if (tmp == NULL) return 0; } diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index e9da27e90a..909b23ef6f 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -344,8 +344,8 @@ SSL *SSL_new(SSL_CTX *ctx) # ifndef OPENSSL_NO_EC if (ctx->tlsext_ecpointformatlist) { s->tlsext_ecpointformatlist = - BUF_memdup(ctx->tlsext_ecpointformatlist, - ctx->tlsext_ecpointformatlist_length); + OPENSSL_memdup(ctx->tlsext_ecpointformatlist, + ctx->tlsext_ecpointformatlist_length); if (!s->tlsext_ecpointformatlist) goto err; s->tlsext_ecpointformatlist_length = @@ -353,8 +353,8 @@ SSL *SSL_new(SSL_CTX *ctx) } if (ctx->tlsext_ellipticcurvelist) { s->tlsext_ellipticcurvelist = - BUF_memdup(ctx->tlsext_ellipticcurvelist, - ctx->tlsext_ellipticcurvelist_length); + OPENSSL_memdup(ctx->tlsext_ellipticcurvelist, + ctx->tlsext_ellipticcurvelist_length); if (!s->tlsext_ellipticcurvelist) goto err; s->tlsext_ellipticcurvelist_length = @@ -3042,7 +3042,7 @@ int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint) } OPENSSL_free(ctx->cert->psk_identity_hint); if (identity_hint != NULL) { - ctx->cert->psk_identity_hint = BUF_strdup(identity_hint); + ctx->cert->psk_identity_hint = OPENSSL_strdup(identity_hint); if (ctx->cert->psk_identity_hint == NULL) return 0; } else @@ -3061,7 +3061,7 @@ int SSL_use_psk_identity_hint(SSL *s, const char *identity_hint) } OPENSSL_free(s->cert->psk_identity_hint); if (identity_hint != NULL) { - s->cert->psk_identity_hint = BUF_strdup(identity_hint); + s->cert->psk_identity_hint = OPENSSL_strdup(identity_hint); if (s->cert->psk_identity_hint == NULL) return 0; } else diff --git a/ssl/ssl_sess.c b/ssl/ssl_sess.c index aff615e0e6..baf846deb7 100644 --- a/ssl/ssl_sess.c +++ b/ssl/ssl_sess.c @@ -249,13 +249,13 @@ SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket) #ifndef OPENSSL_NO_PSK if (src->psk_identity_hint) { - dest->psk_identity_hint = BUF_strdup(src->psk_identity_hint); + dest->psk_identity_hint = OPENSSL_strdup(src->psk_identity_hint); if (dest->psk_identity_hint == NULL) { goto err; } } if (src->psk_identity) { - dest->psk_identity = BUF_strdup(src->psk_identity); + dest->psk_identity = OPENSSL_strdup(src->psk_identity); if (dest->psk_identity == NULL) { goto err; } @@ -274,7 +274,7 @@ SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket) } if (src->tlsext_hostname) { - dest->tlsext_hostname = BUF_strdup(src->tlsext_hostname); + dest->tlsext_hostname = OPENSSL_strdup(src->tlsext_hostname); if (dest->tlsext_hostname == NULL) { goto err; } @@ -282,14 +282,14 @@ SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket) #ifndef OPENSSL_NO_EC if (src->tlsext_ecpointformatlist) { dest->tlsext_ecpointformatlist = - BUF_memdup(src->tlsext_ecpointformatlist, + OPENSSL_memdup(src->tlsext_ecpointformatlist, src->tlsext_ecpointformatlist_length); if (dest->tlsext_ecpointformatlist == NULL) goto err; } if (src->tlsext_ellipticcurvelist) { dest->tlsext_ellipticcurvelist = - BUF_memdup(src->tlsext_ellipticcurvelist, + OPENSSL_memdup(src->tlsext_ellipticcurvelist, src->tlsext_ellipticcurvelist_length); if (dest->tlsext_ellipticcurvelist == NULL) goto err; @@ -297,7 +297,7 @@ SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket) #endif if (ticket != 0) { - dest->tlsext_tick = BUF_memdup(src->tlsext_tick, src->tlsext_ticklen); + dest->tlsext_tick = OPENSSL_memdup(src->tlsext_tick, src->tlsext_ticklen); if(dest->tlsext_tick == NULL) goto err; } else { @@ -307,7 +307,7 @@ SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket) #ifndef OPENSSL_NO_SRP if (src->srp_username) { - dest->srp_username = BUF_strdup(src->srp_username); + dest->srp_username = OPENSSL_strdup(src->srp_username); if (dest->srp_username == NULL) { goto err; } @@ -475,7 +475,7 @@ int ssl_get_new_session(SSL *s, int session) sess_id_done: if (s->tlsext_hostname) { - ss->tlsext_hostname = BUF_strdup(s->tlsext_hostname); + ss->tlsext_hostname = OPENSSL_strdup(s->tlsext_hostname); if (ss->tlsext_hostname == NULL) { SSLerr(SSL_F_SSL_GET_NEW_SESSION, ERR_R_INTERNAL_ERROR); SSL_SESSION_free(ss); diff --git a/ssl/statem/statem_clnt.c b/ssl/statem/statem_clnt.c index 2c2a5215cc..56f6eaf8c5 100644 --- a/ssl/statem/statem_clnt.c +++ b/ssl/statem/statem_clnt.c @@ -2289,9 +2289,8 @@ int tls_construct_client_key_exchange(SSL *s) SSL_R_PSK_IDENTITY_NOT_FOUND); goto psk_err; } - OPENSSL_free(s->s3->tmp.psk); - s->s3->tmp.psk = BUF_memdup(psk, psklen); + s->s3->tmp.psk = OPENSSL_memdup(psk, psklen); OPENSSL_cleanse(psk, psklen); if (s->s3->tmp.psk == NULL) { @@ -2300,7 +2299,6 @@ int tls_construct_client_key_exchange(SSL *s) } s->s3->tmp.psklen = psklen; - identitylen = strlen(identity); if (identitylen > PSK_MAX_IDENTITY_LEN) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_KEY_EXCHANGE, @@ -2308,7 +2306,7 @@ int tls_construct_client_key_exchange(SSL *s) goto psk_err; } OPENSSL_free(s->session->psk_identity); - s->session->psk_identity = BUF_strdup(identity); + s->session->psk_identity = OPENSSL_strdup(identity); if (s->session->psk_identity == NULL) { OPENSSL_cleanse(identity, sizeof(identity)); goto memerr; @@ -2658,7 +2656,7 @@ psk_err: goto err; } OPENSSL_free(s->session->srp_username); - s->session->srp_username = BUF_strdup(s->srp_ctx.login); + s->session->srp_username = OPENSSL_strdup(s->srp_ctx.login); if (s->session->srp_username == NULL) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE); diff --git a/ssl/statem/statem_srvr.c b/ssl/statem/statem_srvr.c index f4c5e8c238..83e56eac31 100644 --- a/ssl/statem/statem_srvr.c +++ b/ssl/statem/statem_srvr.c @@ -2181,7 +2181,7 @@ MSG_PROCESS_RETURN tls_process_client_key_exchange(SSL *s, PACKET *pkt) } OPENSSL_free(s->s3->tmp.psk); - s->s3->tmp.psk = BUF_memdup(psk, psklen); + s->s3->tmp.psk = OPENSSL_memdup(psk, psklen); OPENSSL_cleanse(psk, psklen); if (s->s3->tmp.psk == NULL) { @@ -2534,7 +2534,7 @@ MSG_PROCESS_RETURN tls_process_client_key_exchange(SSL *s, PACKET *pkt) goto f_err; } OPENSSL_free(s->session->srp_username); - s->session->srp_username = BUF_strdup(s->srp_ctx.login); + s->session->srp_username = OPENSSL_strdup(s->srp_ctx.login); if (s->session->srp_username == NULL) { SSLerr(SSL_F_TLS_PROCESS_CLIENT_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE); goto err; diff --git a/ssl/t1_ext.c b/ssl/t1_ext.c index 396ad7e171..2ffe271d97 100644 --- a/ssl/t1_ext.c +++ b/ssl/t1_ext.c @@ -183,7 +183,7 @@ int custom_exts_copy(custom_ext_methods *dst, const custom_ext_methods *src) { if (src->meths_count) { dst->meths = - BUF_memdup(src->meths, + OPENSSL_memdup(src->meths, sizeof(custom_ext_method) * src->meths_count); if (dst->meths == NULL) return 0; diff --git a/ssl/t1_lib.c b/ssl/t1_lib.c index 571a891843..efa04410f2 100644 --- a/ssl/t1_lib.c +++ b/ssl/t1_lib.c @@ -2577,7 +2577,7 @@ static int ssl_scan_serverhello_tlsext(SSL *s, PACKET *pkt, int *al) if (!s->hit && tlsext_servername == 1) { if (s->tlsext_hostname) { if (s->session->tlsext_hostname == NULL) { - s->session->tlsext_hostname = BUF_strdup(s->tlsext_hostname); + s->session->tlsext_hostname = OPENSSL_strdup(s->tlsext_hostname); if (!s->session->tlsext_hostname) { *al = SSL_AD_UNRECOGNIZED_NAME; return 0; diff --git a/ssl/tls_srp.c b/ssl/tls_srp.c index 64a3f23df7..e3763b0f67 100644 --- a/ssl/tls_srp.c +++ b/ssl/tls_srp.c @@ -179,7 +179,7 @@ int SSL_SRP_CTX_init(struct ssl_st *s) goto err; } if ((ctx->srp_ctx.login != NULL) && - ((s->srp_ctx.login = BUF_strdup(ctx->srp_ctx.login)) == NULL)) { + ((s->srp_ctx.login = OPENSSL_strdup(ctx->srp_ctx.login)) == NULL)) { SSLerr(SSL_F_SSL_SRP_CTX_INIT, ERR_R_INTERNAL_ERROR); goto err; } diff --git a/test/dummytest.c b/test/dummytest.c index 5569db09a8..25ce77b2df 100644 --- a/test/dummytest.c +++ b/test/dummytest.c @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) q = p + strlen(p); if (!p) - program = BUF_strdup("(unknown)"); + program = OPENSSL_strdup("(unknown)"); else { program = OPENSSL_malloc((q - p) + 1); strncpy(program, p, q - p); diff --git a/test/enginetest.c b/test/enginetest.c index 54e6eadccd..bbe40e64f5 100644 --- a/test/enginetest.c +++ b/test/enginetest.c @@ -205,9 +205,9 @@ int main(int argc, char *argv[]) printf("About to beef up the engine-type list\n"); for (loop = 0; loop < 512; loop++) { sprintf(buf, "id%i", loop); - id = BUF_strdup(buf); + id = OPENSSL_strdup(buf); sprintf(buf, "Fake engine type %i", loop); - name = BUF_strdup(buf); + name = OPENSSL_strdup(buf); if (((block[loop] = ENGINE_new()) == NULL) || !ENGINE_set_id(block[loop], id) || !ENGINE_set_name(block[loop], name)) { diff --git a/test/evp_test.c b/test/evp_test.c index f24494bbc3..91caa4fc25 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -487,7 +487,7 @@ static int process_test(struct evp_test *t, char *buf, int verbose) key = OPENSSL_malloc(sizeof(*key)); if (!key) return 0; - key->name = BUF_strdup(value); + key->name = OPENSSL_strdup(value); key->key = pk; key->next = *lst; *lst = key; @@ -521,7 +521,7 @@ static int process_test(struct evp_test *t, char *buf, int verbose) fprintf(stderr, "Line %d: multiple result lines\n", t->line); return 0; } - t->expected_err = BUF_strdup(value); + t->expected_err = OPENSSL_strdup(value); if (!t->expected_err) return 0; } else { @@ -554,9 +554,9 @@ static int check_var_length_output(struct evp_test *t, } /* The result printing code expects a non-NULL buffer. */ - t->out_expected = BUF_memdup(expected, expected_len ? expected_len : 1); + t->out_expected = OPENSSL_memdup(expected, expected_len ? expected_len : 1); t->out_expected_len = expected_len; - t->out_received = BUF_memdup(received, received_len ? received_len : 1); + t->out_received = OPENSSL_memdup(received, received_len ? received_len : 1); t->out_received_len = received_len; if (t->out_expected == NULL || t->out_received == NULL) { fprintf(stderr, "Memory allocation error!\n"); @@ -610,7 +610,9 @@ int main(int argc, char **argv) CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); ERR_free_strings(); +#ifdef CRYPTO_MDEBUG CRYPTO_mem_leaks_fp(stderr); +#endif if (t.errors) return 1; return 0; @@ -1052,7 +1054,7 @@ static int mac_test_parse(struct evp_test *t, if (strcmp(keyword, "Key") == 0) return test_bin(value, &mdata->key, &mdata->key_len); if (strcmp(keyword, "Algorithm") == 0) { - mdata->alg = BUF_strdup(value); + mdata->alg = OPENSSL_strdup(value); if (!mdata->alg) return 0; return 1; @@ -1554,7 +1556,7 @@ static int encode_test_init(struct evp_test *t, const char *encoding) edata->encoding = BASE64_VALID_ENCODING; } else if (strcmp(encoding, "invalid") == 0) { edata->encoding = BASE64_INVALID_ENCODING; - t->expected_err = BUF_strdup("DECODE_ERROR"); + t->expected_err = OPENSSL_strdup("DECODE_ERROR"); if (t->expected_err == NULL) return 0; } else { diff --git a/test/exptest.c b/test/exptest.c index 170de09c16..53286d8924 100644 --- a/test/exptest.c +++ b/test/exptest.c @@ -300,7 +300,9 @@ int main(int argc, char *argv[]) BN_free(m); BN_CTX_free(ctx); ERR_remove_thread_state(NULL); +#ifdef CRYPTO_MDEBUG CRYPTO_mem_leaks(out); +#endif BIO_free(out); printf("\n"); diff --git a/test/heartbeat_test.c b/test/heartbeat_test.c index 42cbc0217c..2fa82e3169 100644 --- a/test/heartbeat_test.c +++ b/test/heartbeat_test.c @@ -240,7 +240,7 @@ static int execute_heartbeat(HEARTBEAT_TEST_FIXTURE fixture) result = 1; } else { char *actual_payload = - BUF_strndup((const char *)p, actual_payload_len); + OPENSSL_strndup((const char *)p, actual_payload_len); if (strcmp(actual_payload, fixture.expected_return_payload) != 0) { printf ("%s failed:\n expected payload: \"%s\"\n received: \"%s\"\n", diff --git a/test/ssltest.c b/test/ssltest.c index 0912392649..fd356c7d47 100644 --- a/test/ssltest.c +++ b/test/ssltest.c @@ -253,7 +253,7 @@ typedef struct srp_client_arg_st { static char *ssl_give_srp_client_pwd_cb(SSL *s, void *arg) { SRP_CLIENT_ARG *srp_client_arg = (SRP_CLIENT_ARG *)arg; - return BUF_strdup((char *)srp_client_arg->srppassin); + return OPENSSL_strdup((char *)srp_client_arg->srppassin); } /* SRP server */ diff --git a/util/libeay.num b/util/libeay.num index 98e0ca8fc0..2b5a6221e3 100755 --- a/util/libeay.num +++ b/util/libeay.num @@ -159,7 +159,7 @@ BN_value_one 166 1_1_0 EXIST::FUNCTION: BUF_MEM_free 167 1_1_0 EXIST::FUNCTION: BUF_MEM_grow 168 1_1_0 EXIST::FUNCTION: BUF_MEM_new 169 1_1_0 EXIST::FUNCTION: -BUF_strdup 170 1_1_0 EXIST::FUNCTION: +BUF_strdup 170 1_1_0 NOEXIST::FUNCTION: CONF_free 171 1_1_0 EXIST::FUNCTION: CONF_get_number 172 1_1_0 EXIST::FUNCTION: CONF_get_section 173 1_1_0 EXIST::FUNCTION: @@ -2798,9 +2798,9 @@ X509_REQ_print_ex 3237 1_1_0 EXIST::FUNCTION: ENGINE_up_ref 3238 1_1_0 EXIST::FUNCTION:ENGINE BUF_MEM_grow_clean 3239 1_1_0 EXIST::FUNCTION: CRYPTO_realloc_clean 3240 1_1_0 EXIST::FUNCTION: -BUF_strlcat 3241 1_1_0 EXIST::FUNCTION: +BUF_strlcat 3241 1_1_0 NOEXIST::FUNCTION: BIO_indent 3242 1_1_0 EXIST::FUNCTION: -BUF_strlcpy 3243 1_1_0 EXIST::FUNCTION: +BUF_strlcpy 3243 1_1_0 NOEXIST::FUNCTION: OpenSSLDie 3244 1_1_0 EXIST::FUNCTION: OPENSSL_cleanse 3245 1_1_0 EXIST::FUNCTION: ENGINE_setup_bsd_cryptodev 3246 1_1_0 EXIST:__FreeBSD__:FUNCTION:ENGINE @@ -3062,7 +3062,7 @@ STORE_meth_set_delete_fn 3486 1_1_0 NOEXIST::FUNCTION: STORE_method_set_delete_function 3486 1_1_0 NOEXIST::FUNCTION: STORE_list_certificate_next 3487 1_1_0 NOEXIST::FUNCTION: ASN1_generate_nconf 3488 1_1_0 EXIST::FUNCTION: -BUF_memdup 3489 1_1_0 EXIST::FUNCTION: +BUF_memdup 3489 1_1_0 NOEXIST::FUNCTION: BN_GF2m_mod_mul 3490 1_1_0 EXIST::FUNCTION:EC2M STORE_meth_get_list_next_fn 3491 1_1_0 NOEXIST::FUNCTION: STORE_method_get_list_next_function 3491 1_1_0 NOEXIST::FUNCTION: @@ -3088,7 +3088,7 @@ ECDSA_get_ex_data 3509 1_1_0 NOEXIST::FUNCTION: SHA224 3510 1_1_0 EXIST::FUNCTION: BIO_dump_indent_fp 3511 1_1_0 EXIST::FUNCTION:STDIO EC_KEY_set_group 3512 1_1_0 EXIST::FUNCTION:EC -BUF_strndup 3513 1_1_0 EXIST::FUNCTION: +BUF_strndup 3513 1_1_0 NOEXIST::FUNCTION: STORE_list_certificate_start 3514 1_1_0 NOEXIST::FUNCTION: BN_GF2m_mod 3515 1_1_0 EXIST::FUNCTION:EC2M X509_REQ_check_private_key 3516 1_1_0 EXIST::FUNCTION: @@ -4406,7 +4406,7 @@ X509_VERIFY_PARAM_get0 4762 1_1_0 EXIST::FUNCTION: X509V3_EXT_free 4763 1_1_0 NOEXIST::FUNCTION: BIO_hex_string 4764 1_1_0 EXIST::FUNCTION: X509_VERIFY_PARAM_set_hostflags 4765 1_1_0 EXIST::FUNCTION: -BUF_strnlen 4766 1_1_0 EXIST::FUNCTION: +BUF_strnlen 4766 1_1_0 NOEXIST::FUNCTION: X509_VERIFY_PARAM_get0_peername 4767 1_1_0 EXIST::FUNCTION: ECDSA_METHOD_set_app_data 4768 1_1_0 NOEXIST::FUNCTION: sk_deep_copy 4769 1_1_0 EXIST::FUNCTION: @@ -4742,3 +4742,9 @@ EVP_PKEY_get0_RSA 5104 1_1_0 EXIST::FUNCTION:RSA EC_POINT_point2buf 5105 1_1_0 EXIST::FUNCTION:EC EC_KEY_key2buf 5106 1_1_0 EXIST::FUNCTION:EC EC_KEY_oct2key 5107 1_1_0 EXIST::FUNCTION:EC +OPENSSL_strlcpy 5108 1_1_0 EXIST::FUNCTION: +OPENSSL_strnlen 5109 1_1_0 EXIST::FUNCTION: +OPENSSL_strlcat 5110 1_1_0 EXIST::FUNCTION: +OPENSSL_memdup 5111 1_1_0 NOEXIST::FUNCTION: +CRYPTO_memdup 5112 1_1_0 EXIST::FUNCTION: +CRYPTO_strndup 5113 1_1_0 EXIST::FUNCTION: