diff --git a/test/bio_prefix_text.c b/test/bio_prefix_text.c index c16986fcad..756fe14a3c 100644 --- a/test/bio_prefix_text.c +++ b/test/bio_prefix_text.c @@ -96,7 +96,7 @@ static int setup_bio_chain(const char *progname) BIO *next = NULL; size_t n = amount; - chain = OPENSSL_zalloc(sizeof(*chain) * n); + chain = OPENSSL_calloc(n, sizeof(*chain)); if (chain != NULL) { size_t i; diff --git a/test/bntest.c b/test/bntest.c index 9bb0793677..d7752e7065 100644 --- a/test/bntest.c +++ b/test/bntest.c @@ -2355,7 +2355,7 @@ static int test_rand_range_single(size_t n) unsigned int i, v; int res = 0; - if (!TEST_ptr(counts = OPENSSL_zalloc(sizeof(*counts) * range)) + if (!TEST_ptr(counts = OPENSSL_calloc(range, sizeof(*counts))) || !TEST_ptr(rng = BN_new()) || !TEST_ptr(val = BN_new()) || !TEST_true(BN_set_word(rng, range))) diff --git a/test/ec_internal_test.c b/test/ec_internal_test.c index a8eb33b985..a17e400953 100644 --- a/test/ec_internal_test.c +++ b/test/ec_internal_test.c @@ -549,7 +549,7 @@ static int named_group_creation_test(void) int setup_tests(void) { crv_len = EC_get_builtin_curves(NULL, 0); - if (!TEST_ptr(curves = OPENSSL_malloc(sizeof(*curves) * crv_len)) + if (!TEST_ptr(curves = OPENSSL_malloc_array(crv_len, sizeof(*curves))) || !TEST_true(EC_get_builtin_curves(curves, crv_len))) return 0; diff --git a/test/ecdsatest.c b/test/ecdsatest.c index d79b02a9da..267868e237 100644 --- a/test/ecdsatest.c +++ b/test/ecdsatest.c @@ -399,7 +399,7 @@ int setup_tests(void) /* get a list of all internal curves */ crv_len = EC_get_builtin_curves(NULL, 0); - if (!TEST_ptr(curves = OPENSSL_malloc(sizeof(*curves) * crv_len)) + if (!TEST_ptr(curves = OPENSSL_malloc_array(crv_len, sizeof(*curves))) || !TEST_true(EC_get_builtin_curves(curves, crv_len))) { fake_rand_finish(fake_rand); return 0; diff --git a/test/ectest.c b/test/ectest.c index 24fc7e7d8a..a1bb1a5776 100644 --- a/test/ectest.c +++ b/test/ectest.c @@ -3125,7 +3125,7 @@ static int ec_d2i_publickey_test(void) int setup_tests(void) { crv_len = EC_get_builtin_curves(NULL, 0); - if (!TEST_ptr(curves = OPENSSL_malloc(sizeof(*curves) * crv_len)) + if (!TEST_ptr(curves = OPENSSL_malloc_array(crv_len, sizeof(*curves))) || !TEST_true(EC_get_builtin_curves(curves, crv_len))) return 0; diff --git a/test/evp_kdf_test.c b/test/evp_kdf_test.c index a09470e28f..227b2974d4 100644 --- a/test/evp_kdf_test.c +++ b/test/evp_kdf_test.c @@ -38,7 +38,7 @@ static EVP_KDF_CTX *get_kdfbyname(const char *name) static OSSL_PARAM *construct_tls1_prf_params(const char *digest, const char *secret, const char *seed) { - OSSL_PARAM *params = OPENSSL_malloc(sizeof(OSSL_PARAM) * 4); + OSSL_PARAM *params = OPENSSL_malloc_array(4, sizeof(OSSL_PARAM)); OSSL_PARAM *p = params; if (params == NULL) @@ -194,7 +194,7 @@ static int test_kdf_tls1_prf_1byte_seed(void) static OSSL_PARAM *construct_hkdf_params(char *digest, char *key, size_t keylen, char *salt, char *info) { - OSSL_PARAM *params = OPENSSL_malloc(sizeof(OSSL_PARAM) * 5); + OSSL_PARAM *params = OPENSSL_malloc_array(5, sizeof(OSSL_PARAM)); OSSL_PARAM *p = params; if (params == NULL) @@ -661,7 +661,7 @@ static int test_kdf_hkdf_empty_salt(void) static OSSL_PARAM *construct_pbkdf1_params(char *pass, char *digest, char *salt, unsigned int *iter) { - OSSL_PARAM *params = OPENSSL_malloc(sizeof(OSSL_PARAM) * 5); + OSSL_PARAM *params = OPENSSL_malloc_array(5, sizeof(OSSL_PARAM)); OSSL_PARAM *p = params; if (params == NULL) @@ -781,7 +781,7 @@ err: static OSSL_PARAM *construct_pbkdf2_params(char *pass, char *digest, char *salt, unsigned int *iter, int *mode) { - OSSL_PARAM *params = OPENSSL_malloc(sizeof(OSSL_PARAM) * 6); + OSSL_PARAM *params = OPENSSL_malloc_array(6, sizeof(OSSL_PARAM)); OSSL_PARAM *p = params; if (params == NULL) @@ -1310,7 +1310,7 @@ static int test_kdf_kbkdf_6803_256(void) static OSSL_PARAM *construct_kbkdf_params(char *digest, char *mac, unsigned char *key, size_t keylen, char *salt, char *info, int *r) { - OSSL_PARAM *params = OPENSSL_malloc(sizeof(OSSL_PARAM) * 8); + OSSL_PARAM *params = OPENSSL_malloc_array(8, sizeof(OSSL_PARAM)); OSSL_PARAM *p = params; if (params == NULL) diff --git a/test/evp_pkey_provided_test.c b/test/evp_pkey_provided_test.c index 7e195977ad..0e3955dd96 100644 --- a/test/evp_pkey_provided_test.c +++ b/test/evp_pkey_provided_test.c @@ -2143,7 +2143,7 @@ static int test_check_dsa(void) static OSSL_PARAM *do_construct_hkdf_params(char *digest, char *key, size_t keylen, char *salt) { - OSSL_PARAM *params = OPENSSL_malloc(sizeof(OSSL_PARAM) * 5); + OSSL_PARAM *params = OPENSSL_malloc_array(5, sizeof(OSSL_PARAM)); OSSL_PARAM *p = params; *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, digest, 0); diff --git a/test/evp_test.c b/test/evp_test.c index 4169bd7cba..60a5d0385a 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -4533,7 +4533,7 @@ static int keygen_test_run(EVP_TEST *t) } if (sk_OPENSSL_STRING_num(keygen->in_controls) > 0) { - if ((params = OPENSSL_malloc(sizeof(OSSL_PARAM) * 4)) == NULL) + if ((params = OPENSSL_malloc_array(4, sizeof(OSSL_PARAM))) == NULL) goto err; if (!ctrl2params(t, keygen->in_controls, EVP_PKEY_CTX_settable_params(genctx), diff --git a/test/quic-openssl-docker/hq-interop/quic-hq-interop.c b/test/quic-openssl-docker/hq-interop/quic-hq-interop.c index 0f74e54934..5f7e5b175b 100644 --- a/test/quic-openssl-docker/hq-interop/quic-hq-interop.c +++ b/test/quic-openssl-docker/hq-interop/quic-hq-interop.c @@ -567,21 +567,21 @@ static size_t build_request_set(SSL *ssl) /* * Expand our poll_list, outbiolist, and outnames arrays */ - poll_list = OPENSSL_realloc(poll_list, - sizeof(SSL_POLL_ITEM) * poll_count); + poll_list = OPENSSL_realloc_array(poll_list, + poll_count, sizeof(SSL_POLL_ITEM)); if (poll_list == NULL) { fprintf(stderr, "Unable to realloc poll_list\n"); goto err; } - outbiolist = OPENSSL_realloc(outbiolist, - sizeof(BIO *) * poll_count); + outbiolist = OPENSSL_realloc_array(outbiolist, + poll_count, sizeof(BIO *)); if (outbiolist == NULL) { fprintf(stderr, "Unable to realloc outbiolist\n"); goto err; } - outnames = OPENSSL_realloc(outnames, sizeof(char *) * poll_count); + outnames = OPENSSL_realloc_array(outnames, poll_count, sizeof(char *)); if (outnames == NULL) { fprintf(stderr, "Unable to realloc outnames\n"); goto err; @@ -922,7 +922,8 @@ int main(int argc, char *argv[]) while (req != NULL) { total_requests++; - req_array = OPENSSL_realloc(req_array, sizeof(char *) * total_requests); + req_array = OPENSSL_realloc_array(req_array, + total_requests, sizeof(char *)); if (req_array == NULL) goto end; req_array[total_requests - 1] = req; diff --git a/test/quic_ackm_test.c b/test/quic_ackm_test.c index 07c45c219e..f236c92f23 100644 --- a/test/quic_ackm_test.c +++ b/test/quic_ackm_test.c @@ -112,7 +112,7 @@ static int helper_init(struct helper *h, size_t num_pkts) /* Allocate our array of packet information. */ h->num_pkts = num_pkts; if (num_pkts > 0) { - h->pkts = OPENSSL_zalloc(sizeof(struct pkt_info) * num_pkts); + h->pkts = OPENSSL_calloc(num_pkts, sizeof(struct pkt_info)); if (!TEST_ptr(h->pkts)) goto err; } else { @@ -936,11 +936,11 @@ static int test_rx_ack_actual(int tidx, int space) num_tx += s->num_pn; /* Allocate packet information structures. */ - txs = OPENSSL_zalloc(sizeof(*txs) * num_tx); + txs = OPENSSL_calloc(num_tx, sizeof(*txs)); if (!TEST_ptr(txs)) goto err; - pkts = OPENSSL_zalloc(sizeof(*pkts) * num_tx); + pkts = OPENSSL_calloc(num_tx, sizeof(*pkts)); if (!TEST_ptr(pkts)) goto err; diff --git a/test/quic_multistream_test.c b/test/quic_multistream_test.c index e262dfd467..51a16db0ea 100644 --- a/test/quic_multistream_test.c +++ b/test/quic_multistream_test.c @@ -1886,7 +1886,7 @@ static int run_script_worker(struct helper *h, const struct script_op *script, goto out; } - h->threads = OPENSSL_zalloc(op->arg1 * sizeof(struct child_thread_args)); + h->threads = OPENSSL_calloc(op->arg1, sizeof(struct child_thread_args)); if (!TEST_ptr(h->threads)) goto out; diff --git a/test/slh_dsa_test.c b/test/slh_dsa_test.c index 2eb7e797e9..43e188903b 100644 --- a/test/slh_dsa_test.c +++ b/test/slh_dsa_test.c @@ -480,7 +480,7 @@ static int slh_dsa_deterministic_usage_test(void) if (!TEST_int_eq(EVP_PKEY_sign(sctx, NULL, &sig_len, msg, msg_len), 1)) goto err; len = sig_len; - if (!TEST_ptr(sig = OPENSSL_zalloc(sig_len * 2)) + if (!TEST_ptr(sig = OPENSSL_calloc(2, sig_len)) || !TEST_int_eq(EVP_PKEY_sign(sctx, sig, &len, msg, msg_len), 1) || !TEST_size_t_eq(sig_len, len) || !TEST_int_eq(EVP_PKEY_sign(dupctx, sig + sig_len, &len, diff --git a/test/sslapitest.c b/test/sslapitest.c index d4450b01d4..fc574519a8 100644 --- a/test/sslapitest.c +++ b/test/sslapitest.c @@ -7969,7 +7969,7 @@ static int ssl_srp_cb(SSL *s, int *ad, void *arg) static int create_new_vfile(char *userid, char *password, const char *filename) { char *gNid = NULL; - OPENSSL_STRING *row = OPENSSL_zalloc(sizeof(row) * (DB_NUMBER + 1)); + OPENSSL_STRING *row = OPENSSL_calloc(DB_NUMBER + 1, sizeof(row)); TXT_DB *db = NULL; int ret = 0; BIO *out = NULL, *dummy = BIO_new_mem_buf("", 0); diff --git a/test/sslcorrupttest.c b/test/sslcorrupttest.c index 50c3bf7eeb..d1f9752132 100644 --- a/test/sslcorrupttest.c +++ b/test/sslcorrupttest.c @@ -154,8 +154,8 @@ static int setup_cipher_list(void) * so that some of the allocated space will be wasted, but the loss * is deemed acceptable... */ - cipher_list = OPENSSL_malloc(sk_SSL_CIPHER_num(sk_ciphers) * - sizeof(cipher_list[0])); + cipher_list = OPENSSL_malloc_array(sk_SSL_CIPHER_num(sk_ciphers), + sizeof(cipher_list[0])); if (!TEST_ptr(cipher_list)) goto err; diff --git a/test/testutil/format_output.c b/test/testutil/format_output.c index 0a0f464ca1..b6d8facbfe 100644 --- a/test/testutil/format_output.c +++ b/test/testutil/format_output.c @@ -299,7 +299,7 @@ static void test_fail_bignum_common(const char *prefix, const char *file, len = ((l1 > l2 ? l1 : l2) + bytes - 1) / bytes * bytes; - if (len > MEM_BUFFER_SIZE && (bufp = OPENSSL_malloc(len * 2)) == NULL) { + if (len > MEM_BUFFER_SIZE && (bufp = OPENSSL_malloc_array(2, len)) == NULL) { bufp = buffer; len = MEM_BUFFER_SIZE; test_printf_stderr("WARNING: these BIGNUMs have been truncated\n");