From: Eugene Syromiatnikov Date: Wed, 23 Jul 2025 13:49:18 +0000 (+0200) Subject: apps, fuzz, providers: use array memory (re)allocation routines X-Git-Tag: openssl-3.6.0-alpha1~219 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f3a4d05c5889b571d8b99c645fa41533b27ec44b;p=thirdparty%2Fopenssl.git apps, fuzz, providers: use array memory (re)allocation routines Co-Authored-by: Alexandr Nedvedicky Signed-off-by: Eugene Syromiatnikov Reviewed-by: Saša Nedvědický Reviewed-by: Matt Caswell Reviewed-by: Paul Dale Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/28059) --- diff --git a/apps/lib/apps.c b/apps/lib/apps.c index f005d71ddea..50e83b50c42 100644 --- a/apps/lib/apps.c +++ b/apps/lib/apps.c @@ -106,7 +106,8 @@ int chopup_args(ARGS *arg, char *buf) char **tmp; arg->size += 20; - tmp = OPENSSL_realloc(arg->argv, sizeof(*arg->argv) * arg->size); + tmp = OPENSSL_realloc_array(arg->argv, + arg->size, sizeof(*arg->argv)); if (tmp == NULL) return 0; arg->argv = tmp; @@ -3461,7 +3462,7 @@ OSSL_PARAM *app_params_new_from_opts(STACK_OF(OPENSSL_STRING) *opts, if (opts == NULL) return NULL; - params = OPENSSL_zalloc(sizeof(OSSL_PARAM) * (sz + 1)); + params = OPENSSL_calloc(sz + 1, sizeof(OSSL_PARAM)); if (params == NULL) return NULL; diff --git a/apps/lib/vms_decc_argv.c b/apps/lib/vms_decc_argv.c index 031e5afdeca..1a2781d1686 100644 --- a/apps/lib/vms_decc_argv.c +++ b/apps/lib/vms_decc_argv.c @@ -56,7 +56,7 @@ char **copy_argv(int *argc, char *argv[]) * get them when linking with all of libapps.a. * See comment in test/build.info. */ - newargv = OPENSSL_malloc(sizeof(*newargv) * (count + 1)); + newargv = OPENSSL_malloc_array(count + 1, sizeof(*newargv)); if (newargv == NULL) return NULL; diff --git a/apps/x509.c b/apps/x509.c index 6051d8642f0..c9d26f8b203 100644 --- a/apps/x509.c +++ b/apps/x509.c @@ -1303,7 +1303,7 @@ static int print_x509v3_exts(BIO *bio, X509 *x, const char *ext_names) BIO_printf(bio, "Invalid extension names: %s\n", ext_names); goto end; } - if ((names = OPENSSL_malloc(sizeof(char *) * nn)) == NULL) + if ((names = OPENSSL_malloc_array(nn, sizeof(char *))) == NULL) goto end; parse_ext_names(tmp_ext_names, names); diff --git a/fuzz/hashtable.c b/fuzz/hashtable.c index 38d22950763..6fc033b3e6c 100644 --- a/fuzz/hashtable.c +++ b/fuzz/hashtable.c @@ -103,7 +103,7 @@ int FuzzerInitialize(int *argc, char ***argv) OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); ERR_clear_error(); - prediction_table = OPENSSL_zalloc(sizeof(FUZZER_VALUE) * 65537); + prediction_table = OPENSSL_calloc(65537, sizeof(FUZZER_VALUE)); if (prediction_table == NULL) return -1; fuzzer_table = ossl_ht_new(&fuzz_conf); diff --git a/fuzz/provider.c b/fuzz/provider.c index 3133861d342..8f3c972ba54 100644 --- a/fuzz/provider.c +++ b/fuzz/provider.c @@ -270,7 +270,7 @@ static OSSL_PARAM *fuzz_params(OSSL_PARAM *param, const uint8_t **buf, size_t *l for (p = param; p != NULL && p->key != NULL; p++) p_num++; - fuzzed_parameters = OPENSSL_zalloc(sizeof(OSSL_PARAM) *(p_num + 1)); + fuzzed_parameters = OPENSSL_calloc(p_num + 1, sizeof(OSSL_PARAM)); p = fuzzed_parameters; for (; param != NULL && param->key != NULL; param++) { diff --git a/providers/implementations/encode_decode/ml_common_codecs.c b/providers/implementations/encode_decode/ml_common_codecs.c index 773550c9fb9..ec9c49a4d43 100644 --- a/providers/implementations/encode_decode/ml_common_codecs.c +++ b/providers/implementations/encode_decode/ml_common_codecs.c @@ -42,7 +42,7 @@ ossl_ml_common_pkcs8_fmt_order(const char *algorithm_name, const char *sep = "\t ,"; /* Reserve an extra terminal slot with fmt == NULL */ - if ((ret = OPENSSL_zalloc((NUM_PKCS8_FORMATS + 1) * sizeof(*ret))) == NULL) + if ((ret = OPENSSL_calloc(NUM_PKCS8_FORMATS + 1, sizeof(*ret))) == NULL) return NULL; /* Entries that match a format will get a non-zero preference. */ diff --git a/providers/implementations/kdfs/argon2.c.in b/providers/implementations/kdfs/argon2.c.in index afaf9dbfd15..79961b4db8b 100644 --- a/providers/implementations/kdfs/argon2.c.in +++ b/providers/implementations/kdfs/argon2.c.in @@ -569,8 +569,8 @@ static int fill_mem_blocks_mt(KDF_ARGON2 *ctx) void **t; ARGON2_THREAD_DATA *t_data; - t = OPENSSL_zalloc(sizeof(void *)*ctx->lanes); - t_data = OPENSSL_zalloc(ctx->lanes * sizeof(ARGON2_THREAD_DATA)); + t = OPENSSL_calloc(ctx->lanes, sizeof(void *)); + t_data = OPENSSL_calloc(ctx->lanes, sizeof(ARGON2_THREAD_DATA)); if (t == NULL || t_data == NULL) goto fail; @@ -738,11 +738,9 @@ static int initialize(KDF_ARGON2 *ctx) return 0; if (ctx->type != ARGON2_D) - ctx->memory = OPENSSL_secure_zalloc(ctx->memory_blocks * - sizeof(BLOCK)); + ctx->memory = OPENSSL_secure_calloc(ctx->memory_blocks, sizeof(BLOCK)); else - ctx->memory = OPENSSL_zalloc(ctx->memory_blocks * - sizeof(BLOCK)); + ctx->memory = OPENSSL_calloc(ctx->memory_blocks, sizeof(BLOCK)); if (ctx->memory == NULL) { ERR_raise_data(ERR_LIB_PROV, PROV_R_INVALID_MEMORY_SIZE,